• vue3中使用WangEditor 富文本编辑器


    附官网:https://www.wangeditor.com/

    1.安装 + 引入

    1. npm install @wangeditor/editor --save
    2. // 组件中
    3. import "@wangeditor/editor/dist/css/style.css"; // 引入 css
    4. import { Editor, Toolbar } from "@wangeditor/editor-for-vue";

    2.组件template模板中 

    1.  
      "border: 1px solid #ccc">
    2.           <Toolbar
    3.             style="border-bottom: 1px solid #ccc"
    4.             :editor="editorRef"
    5.             :defaultConfig="toolbarConfig"
    6.           />
    7.           <Editor
    8.             style="height: 300px; overflow-y: hidden"
    9.             v-model="newsParameterList.news_content"
    10.             @onCreated="handleCreated"
    11.             :defaultConfig="editorConfig"
    12.           />
  • // newsParameterList.news_content 为富文本内容绑定
  • 3.具体配置

    1. import { shallowRef } from "vue";
    2. //编辑器实例,必须用 shallowRef
    3. let editorRef = shallowRef();
    4. let handleCreated = (editor: any) => {
    5. editorRef.value = editor; // 记录 editor 实例,重要!
    6. };
    7. // 菜单配置项 删除没有太大用途的菜单项
    8. let toolbarConfig = {
    9. excludeKeys: [
    10. "insertVideo", // 删除视频
    11. "uploadVideo",
    12. "group-video",
    13. "insertImage", // 删除网络图片上传
    14. "insertLink", // 删除链接
    15. "insertTable", // 删除表格
    16. "codeBlock", // 删除代码块
    17. "blockquote",
    18. "todo",
    19. "emotion",
    20. "fontSize",
    21. "fontFamily",
    22. "lineHeight",
    23. "group-more-style",
    24. "color",
    25. "bgColor",
    26. ],
    27. };
    28. //编辑器实例,必须用 shallowRef
    29. let editorRef = shallowRef();
    30. let handleCreated = (editor: any) => {
    31. editorRef.value = editor; // 记录 editor 实例,重要!
    32. };
    33. const editorConfig = {
    34. MENU_CONF: {
    35. uploadImage: {
    36. server: "/api/upload",
    37. allowedFileTypes: ["image/*"],
    38. fieldName: "your-fileName",
    39. base64LimitSize: 3 * 1024 * 1024,
    40. // 单个文件的最大体积限制,为 3M
    41. maxFileSize: 3 * 1024 * 1024,
    42. maxNumberOfFiles: 1,
    43. onError(file: any) {
    44. proxy.$message.warning("当前选择的图片过大!请选择3M以内");
    45. },
    46. },
    47. },
    48. };

    4.编辑回显

    1. //编辑器实例,必须用 shallowRef
    2. let editorRef = shallowRef();
    3. let handleCreated = (editor: any) => {
    4. editorRef.value = editor; // 记录 editor 实例,重要!
    5. newsDetails().then(() => {
    6. if (newEditsList.value.news_content) {
    7. //回显
    8. editor.setHtml(newEditsList.value.news_content);
    9. }
    10. });
    11. };

  • 相关阅读:
    Regular polygon
    你不知道的自然语言处理应用场景和挑战
    IPSEC的原理及配置步骤整理(一)
    不同版本vue安装vue-router
    SpringCloud微服务架构实践详细汇总
    java---类加载器
    R语言中的prophet预测时间序列数据模型
    记一次:jenkins自动化部署服务
    金融行业数据库类应用分布式存储的评测方法与实践经验
    数据库设计规范
  • 原文地址:https://blog.csdn.net/m0_65544665/article/details/133749754