• vue使用wangEditor


    vue版本2.0;editor5.1.23版本;editor-for-vue:1.0.2版本
    在这里插入图片描述
    api文档入口
    效果图
    在这里插入图片描述
    点击查看如何封装
    安装步骤入口

    npm install @wangeditor/editor --save
    
    • 1
    npm install @wangeditor/editor-for-vue --save
    
    • 1

    代码(未封装过的)

    <template>
      <div>
        <div style="border: 1px solid #ccc">
          <toolbar
            style="border-bottom: 1px solid #ccc"
            :editor="editor"
            :defaultConfig="toolbarConfig"
            :mode="mode"
          />
          <editor
            style="height: 500px; overflow-y: hidden"
            v-model="html"
            :defaultConfig="defaultEditorConfig"
            :mode="mode"
            @onCreated="onCreated"
          />
        </div>
        <div>
          <a-button type="primary" @click="htmlContent"> 请点我 </a-button>
        </div>
      </div>
    </template>
    <script>
    import Vue from "vue";
    import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
    const toolbarConfig = {};
    toolbarConfig.excludeKeys = [
      "todo", //待办
      "emotion", //表情
      "insertLink", //超链接
      "insertVideo", //表情
      "group-video", //视频
      "codeBlock", //代码块
      "divider", //分割线
    ];
    const defaultEditorConfig = {
      // JS 语法
      MENU_CONF: {},
      // 其他属性...
    };
    // 修改 uploadImage 菜单配置
    defaultEditorConfig.MENU_CONF["uploadImage"] = {
      server: "后端提供的上传图片接口",
      fieldName: "file",
      //【注意】不需要修改的不用写,wangEditor 会去 merge 当前其他配置
    };
    export default Vue.extend({
      components: { Editor, Toolbar },
      data() {
        return {
          editor: null,
          html: "

    hello

    "
    , toolbarConfig: toolbarConfig, defaultEditorConfig: defaultEditorConfig, mode: "default", // or 'simple' }; }, methods: { //编辑器创建完毕时的回调函数。 onCreated(editor) { this.editor = Object.seal(editor); // 一定要用 Object.seal() ,否则会报错 console.log(this.editor); }, htmlContent() { console.log(this.html); }, }, mounted() { // 模拟 ajax 请求,异步渲染编辑器 setTimeout(() => { this.html = "

    模拟 Ajax 异步设置内容 HTML

    "
    ; }, 1500); }, beforeDestroy() { const editor = this.editor; if (editor == null) return; editor.destroy(); // 组件销毁时,及时销毁编辑器 }, }); </script> <style src="@wangeditor/editor/dist/css/style.css"></style>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81

    后端提供的上传图片接口响应格式需要按照wangEditor的来
    在这里插入图片描述
    excludeKeys可以排除掉某些不想要的菜单,其他都保留
    放在defaultConfig事件里

     	<toolbar
            style="border-bottom: 1px solid #ccc"
            :editor="editor"
            :defaultConfig="toolbarConfig"
            :mode="mode"
          />
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    const toolbarConfig = {};
    toolbarConfig.excludeKeys = [
      "todo", //待办
      "emotion", //表情
      "insertLink", //超链接
      "insertVideo", //表情
      "group-video", //视频
      "codeBlock", //代码块
      "divider", //分割线
    ];
    data() {
        return {
          toolbarConfig: toolbarConfig,
        };
      },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    toolbarConfig.excludeKeys里面的key去哪里看?文档上面我是没有找到 哎
    我是先打开官网上面的demo示例,再打开控制台然后在console下面输入toolbar找到的
    在这里插入图片描述

  • 相关阅读:
    动态规划-买卖股票系列
    c# PDFSharp 给已有的pdf文件添加文字页脚(文字水印)
    vue定时器
    LCD12864 Control Sequence &Command Reference
    设计模式~备忘录模式(memento)-22
    Docker 网络与数据管理
    设计通用流程和可变点的方法一些思考
    PTA古风排版
    批量多字段唯一性校验
    计组错题集
  • 原文地址:https://blog.csdn.net/weixin_44860425/article/details/132721854