• 小知识(7) wangEditor富文本编辑器简单引入(vue3)


    wangEditor富文本编辑器

    • https://github.com/wangeditor-team/wangEditor
    • https://www.wangeditor.com/

    一、安装

    1. cnpm install @wangeditor/editor --save
    2. cnpm install @wangeditor/editor-for-vue@next --save

    二、使用

    BaseEditor.vue
    1. <template>
    2. <div style="border: 1px solid #ccc">
    3. <Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :default-config="toolbarConfig" :mode="mode" />
    4. <Editor v-bind="$attrs" style="height: 500px; overflow-y: hidden" :default-config="editorConfig" :mode="mode" @onCreated="handleCreated" />
    5. </div>
    6. </template>
    7. <script setup>
    8. const { proxy } = getCurrentInstance();
    9. import '@wangeditor/editor/dist/css/style.css'; // 引入 css
    10. import { onBeforeUnmount, ref, shallowRef, onMounted } from 'vue';
    11. import { Editor, Toolbar } from '@wangeditor/editor-for-vue';
    12. // 编辑器实例,必须用 shallowRef
    13. const editorRef = shallowRef();
    14. let mode = ref('default'); // 'default''simple'
    15. onMounted(() => {});
    16. const toolbarConfig = {};
    17. const editorConfig = { placeholder: '请输入内容...' };
    18. // 组件销毁时,也及时销毁编辑器
    19. onBeforeUnmount(() => {
    20. const editor = editorRef.value;
    21. if (editor == null) return;
    22. editor.destroy();
    23. });
    24. const handleCreated = (editor) => {
    25. editorRef.value = editor; // 记录 editor 实例,重要!
    26. };
    27. </script>
    28. <style lang="scss" scoped></style>
    测试
    1. <template>
    2. <base-Editor v-model="valueHtml" />
    3. </template>
    4. <script setup>
    5. const { proxy } = getCurrentInstance();
    6. let valueHtml = ref('

      hello

      '
      );
    7. </script>
    8. <style lang="scss" scoped></style>

     

  • 相关阅读:
    QT打开网页或者资源管理器:QDesktopServices以及QSettings 用法
    26个开发者常用必备网站汇总推荐
    零基础小白学习 Java 要经历的阶段!
    FreeSWITCH 1.10 源码阅读(1)-服务启动及 Event Socket 模块工作原理
    网络安全(补充)
    git使用看这一篇就够了
    react-ref与ref转发
    Higg FEM的一些小技巧
    电压频率的变换原理
    【2020.09.01】 新学期,新气象
  • 原文地址:https://blog.csdn.net/qq_38225558/article/details/134010506