ToB企服应用市场:ToB评测及商务社交产业平台

标题: wangEditor工具栏相关配置设置 [打印本页]

作者: 没腿的鸟    时间: 2024-10-11 16:50
标题: wangEditor工具栏相关配置设置
官网地址:wangEditor
编辑器效果图如下:

安装下令:
  1. yarn方式安装
  2. #方法1,安装 editor
  3. yarn add @wangeditor/editor
  4. #方法2,安装 Vue2 组件
  5. yarn add @wangeditor/editor-for-vue
  6. #方法3,安装 Vue3 组件
  7. yarn add @wangeditor/editor-for-vue@next
  8. npm方式安装
  9. #方法1,安装 editor
  10. npm install @wangeditor/editor --save
  11. #方法2,安装 Vue2 组件
  12. npm install @wangeditor/editor-for-vue --save
  13. #方法3,安装 Vue3 组件
  14. npm install @wangeditor/editor-for-vue@next --save
复制代码

利用方式,vue中
  1. <template>
  2.     <div style="border: 1px solid #ccc;">
  3.         <Toolbar
  4.             style="border-bottom: 1px solid #ccc"
  5.             :editor="editor"
  6.             :defaultConfig="toolbarConfig"
  7.             :mode="mode"
  8.         />
  9.         <Editor
  10.             style="height: 500px; overflow-y: hidden;"
  11.             v-model="html"
  12.             :defaultConfig="editorConfig"
  13.             :mode="mode"
  14.             @onCreated="onCreated"
  15.         />
  16.     </div>
  17. </template>
  18. <script>
  19. import Vue from 'vue'
  20. import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
  21. export default Vue.extend({
  22.     components: { Editor, Toolbar },
  23.     data() {
  24.         return {
  25.             editor: null,
  26.             html: '<p>hello</p>',
  27.             toolbarConfig: { },
  28.             editorConfig: { placeholder: '请输入内容...' },
  29.             mode: 'default', // or 'simple'
  30.         }
  31.     },
  32.     methods: {
  33.         onCreated(editor) {
  34.             this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
  35.         },
  36.     },
  37.     mounted() {
  38.         // 模拟 ajax 请求,异步渲染编辑器
  39.         setTimeout(() => {
  40.             this.html = '<p>模拟 Ajax 异步设置内容 HTML</p>'
  41.         }, 1500)
  42.     },
  43.     beforeDestroy() {
  44.         const editor = this.editor
  45.         if (editor == null) return
  46.         editor.destroy() // 组件销毁时,及时销毁编辑器
  47.     }
  48. })
  49. </script>
复制代码
工具栏参数设置说明
  1. toolbarConfig: {
  2.         excludeKeys: [
  3.           "headerSelect",// 标题
  4.           "blockquote", // 引用
  5.           "bold", // 加粗
  6.           "underline", // 下划线
  7.           "italic", // 斜体
  8.           // 删除线、清除格式等
  9.           "group-more-style",
  10.           {
  11.             key: "group-more-style",
  12.             title: "更多",
  13.             iconSvg:
  14.               '<svg viewBox="0 0 1024 1024"><path d="M204.8 505.6…0 153.6 0 76.8 76.8 0 1 0-153.6 0Z"></path></svg>',
  15.             menuKeys: Array(5)
  16.           },
  17.           "color", // 文字颜色
  18.           "bgColor", // 背景色
  19.           "fontSize", // 字号
  20.           "fontFamily", // 字体
  21.           "lineHeight", // 行高
  22.           "bulletedList", // 无序列表
  23.           "numberedList", // 有序列表
  24.           "todo", // 代办
  25.           // 对齐
  26.           "group-justify",
  27.           {
  28.             key: "group-justify",
  29.             title: "对齐",
  30.             iconSvg:
  31.               '<svg viewBox="0 0 1024 1024"><path d="M768 793.6v1…72.8 102.4v102.4H51.2V102.4h921.6z"></path></svg>',
  32.             menuKeys: Array(4)
  33.           },
  34.           // 缩进
  35.           "group-indent"
  36.           {
  37.             key: "group-indent",
  38.             title: "缩进",
  39.             iconSvg:
  40.               '<svg viewBox="0 0 1024 1024"><path d="M0 64h1024v1…32h1024v128H0z m0-128V320l256 192z"></path></svg>',
  41.             menuKeys: Array(2)
  42.           },
  43.           "emotion",// 表情
  44.           "insertLink",// 插入链接
  45.           // 上传图片
  46.           {
  47.             key: "group-image",
  48.             title: "图片",
  49.             iconSvg:
  50.               '<svg viewBox="0 0 1024 1024"><path d="M959.877 128…l224.01-384 256 320h64l224.01-192z"></path></svg>',
  51.             menuKeys: Array(2)
  52.           },
  53.           // 上传视频
  54.           {
  55.             key: "group-video",
  56.             title: "视频",
  57.             iconSvg:
  58.               '<svg viewBox="0 0 1024 1024"><path d="M981.184 160….904zM384 704V320l320 192-320 192z"></path></svg>',
  59.             menuKeys: Array(2)
  60.           },
  61.           "insertTable",// 插入表格
  62.           "codeBlock", // 代码块
  63.           "divider", // 分割线
  64.           "undo", // 撤销
  65.           "redo", // 重做
  66.           "fullScreen" // 全屏
  67.           ]
  68.       }
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4