vue項(xiàng)目使用百度編輯器

1.下載ueditor包放入public static里面
2.創(chuàng)建一個(gè)ueditor.vue

<template>
  <div>
    <script id="editor" type="text/plain" ></script>
  </div>
</template>

<script>
  import '你的路徑/static/UEditor/ueditor.config.js'
  import '你的路徑/public/static/UEditor/ueditor.all.js'
  import '你的路徑/public/static/UEditor/lang/zh-cn/zh-cn.js'
  import '你的路徑/public/static/UEditor/jquery-2.2.3.min.js'

  export default {
    name: "UEditor",
    props: {
      id: {
          type: String
      },
      config: {
          type: Object
      }
    },
    data() {
      return {
        editor: null
      }
    },
    mounted() {
      //初始化UE
      const _this = this;
      this.editor = UE.delEditor("editor");
      this.editor = UE.getEditor('editor',this.config);
    },
    destoryed() {
      this.editor.destory();
    },
    methods:{
      getUEContent: function(){
       return this.editor.getContent();
      },
      getContentTxt: function(){
        return this.editor.getContentTxt();
      }
    }
  }
</script>

3.需要用到編輯的頁面 先引入ueditor.vue

<ueditor  :config='config' ref="ue"></ueditor>

this.$refs.ue.getUEContent()獲取編輯器的內(nèi)容。

4.圖片上傳配置

ueditor.config.js

window.UEDITOR_HOME_URL = "/static/UEditor/"; //引入包的位置 22行左右
//window.UEDITOR_CONFIG里的serverUrl:“服務(wù)器接口url”

如果需配置token,則需要在ueditor.all.js里,約8242行,加上token

xhr.setRequestHeader('Authorization', 'Bearer '+JSON.parse(window.sessionStorage.getItem("token")).token);
if (method == "POST") {
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.send(submitStr);
  } else {
      xhr.send(null);
  }

上傳圖片攜帶token,dialogs/image/image.js 大約704行

uploader.on('uploadBeforeSend', function (file, data, header) {
                //這里可以通過data對(duì)象添加POST參數(shù)
                header['X_Requested_With'] = 'XMLHttpRequest';
                header['Authorization'] = 'Bearer '+JSON.parse(window.sessionStorage.getItem("token")).token;
            });

視頻攜帶token,dialogs/video/video.js,大約717行

uploader.on('uploadBeforeSend', function (file, data, header) {
                //這里可以通過data對(duì)象添加POST參數(shù)
                header['X_Requested_With'] = 'XMLHttpRequest';
                header['Authorization'] = 'Bearer '+JSON.parse(window.sessionStorage.getItem("token")).token;
            });

5.我是在彈框里加的編輯器,出現(xiàn)過工具欄和內(nèi)容框分離的情況
解決方法是在ueditor.config.js里大約296行autoFloatEnabled改為false

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容