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