美文网首页
vue2中Ueditor富文本编辑器的使用

vue2中Ueditor富文本编辑器的使用

作者: 陶菇凉 | 来源:发表于2022-12-07 16:27 被阅读0次

    一、下载Ueditor

    官网地址:http://fex.baidu.com/ueditor/
    git地址: https://github.com/fex-team/ueditor

    二、编译下载文件

    1、执行命令安装依赖:

    npm install
    

    2、全局安装Grunt-cli:

    npm install -g grunt-cli   
    

    3、安装到本地:

    npm install grunt --save-dev
    

    4、执行编译命令

    grunt default
    

    三、在Vue项目中引用

    编译成功之后会生成一个 dist 文件夹,里面是我们要的编译后的文件,将 utf8-php 文件复制到 vue项目里的 public 文件夹里 ,将utf8-php重命名为UEditor便于使用
    1、下载vue-ueditor-wrap

    npm i vue-ueditor-wrap
    

    2、在vue项目中引入

    <template>
      <div class="ue">
        <vue-ueditor-wrap v-model="data" :config="myConfig"></vue-ueditor-wrap>
      </div>
    </template>
     
    <script>
    import VueUeditorWrap from "vue-ueditor-wrap";
     
    export default {
      components: {
        VueUeditorWrap,
      },
      data() {
        return {
          data: "dome",
          myConfig: {
            // 设置编辑器不自动被内容撑高
            autoHeightEnabled: false,
            // 初始容器高度
            initialFrameHeight: 320,
            // 初始容器宽度
            initialFrameWidth: "100%",
            // 可以放后台存放路径
            serverUrl: "",
            // UEditor 是文件的存放路径,
            UEDITOR_HOME_URL: "/UEditor/",
          },
        };
      },
    };
    </script>
    

    四、修改配置文件

    在ueditor.config.js中,需要修改

    window.UEDITOR_HOME_URL ='/public/Ueditor/'
    

    否则线上部署会找不到资源。

    相关文章

      网友评论

          本文标题:vue2中Ueditor富文本编辑器的使用

          本文链接:https://www.haomeiwen.com/subject/malifdtx.html