Vue中使用wangeditor富文本編輯的問(wèn)題
wangEditor是基于javascript和css開(kāi)發(fā)的 Web富文本編輯器, 輕量、簡(jiǎn)潔、易用、開(kāi)源免費(fèi)。
在我們實(shí)際項(xiàng)目上還是比較頻繁應(yīng)用到的,下面出個(gè)案例供大家參考學(xué)習(xí)…
wangEditor文檔:https://www.wangeditor.com/
富文本編輯器截圖:



<!--富文本編輯器。http://www.wangeditor.com/
使用示例:
<AppEditor v-model="content"></AppEditor>
-->
<template>
<article ref="editor" class="AppEditor-root"></article>
</template>
<script>
const E = require('wangeditor');
export default {
name: 'AppEditor',
model: {
prop: 'value',
event: 'update:value',
},
props: {
// value值,v-model綁定
value: {type: String, default: ''},
// 菜單選項(xiàng)
menus: {
type: Array,
default(){
return [
'bold', // 粗體
'italic',//斜體
'underline',//下劃線
'fontSize', // 字號(hào)
'strikeThrough',//刪除線
'image', // 插入圖片
'undo', // 撤銷(xiāo)
// 'fontName', // 字體
// 'italic', // 斜體
// 'underline', // 下劃線
// 'strikeThrough', // 刪除線
// 'foreColor', // 文字顏色
// 'backColor', // 背景顏色
// 'link', // 插入鏈接
// 'list', // 列表
// 'justify', // 對(duì)齊方式
// 'quote', // 引用
// 'emoticon', // 表情
// 'image', // 插入圖片
// 'table', // 表格
// 'video', // 插入視頻
// 'code', // 插入代碼
// 'undo', // 撤銷(xiāo)
// 'redo', // 重復(fù)
];
},
},
},
data(){
return {
editor: {}, // 編輯器對(duì)象
_value: '', // 內(nèi)容備份,用于watch時(shí)候判斷,只在編輯器輸入時(shí)改變
};
},
computed: {},
mounted(){
this.initEditor();
},
watch: {
value(newValue, oldValue){
// 編輯器onchange更改的不處理,只處理父組件傳來(lái)的,防止文字回退bug
if (newValue != this._value) {
this.editor.txt.html(newValue);
}
},
},
methods: {
initEditor(){
let editor = new E(this.$refs.editor);
Object.assign(editor.customConfig, {
menus: this.menus,
zIndex: 100,
height: 200,
pasteFilterStyle: false,
onchange: (html) => {
this._value = html; // 更新 _value
this.$emit('update:value', html); // 更新 value
},
customUploadImg:((file, insert)=> {
if(this.$utils.isEmpty(file)){
return;
}
const msg = this.$Message.loading({
content: '親,圖片正在拼命地上傳中,請(qǐng)稍等...',
duration: 0
});
var params = new FormData();
params.append('img', file[0]);
this.$api.post('/synthesis/crm/picture/pictureUpload',params).then(res => {
insert(res.data.imgUrl)
setTimeout(msg, 0);
this.$Message.success('上傳成功');
})
}),
uploadImgHooks:{
customInsert: function (insertImg, result, editor) {
insertImg(result.url)
}
}
});
editor.create();
editor.txt.html(this.value); // 針對(duì)數(shù)據(jù)異步獲取的這里無(wú)法立即綁定,在watch判斷處理
this.editor = editor;
},
},
};
</script>
<style scoped lang="scss">
.AppEditor-root{ border: 1px solid #f0f0f0; height: 400px !important;
/deep/ .w-e-toolbar{ border: none !important; border-bottom: 1px solid #f0f0f0 !important; background-color: #fff !important;
}
/deep/ .w-e-text-container{ height: calc(100% - 43px) !important; border: none !important; z-index:1 !important;
.w-e-text{ height: 100%; overflow-y: auto !important;}
}
}
</style>
到此這篇關(guān)于Vue中使用wangeditor富文本編輯的問(wèn)題的文章就介紹到這了,更多相關(guān)wangeditor富文本編輯內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue2之jessibuca視頻插件使用教程詳細(xì)講解
Jessibuca進(jìn)行直播流播放,為用戶帶來(lái)便捷、高效的視頻觀看體驗(yàn),下面這篇文章主要給大家介紹了關(guān)于vue2之jessibuca視頻插件使用的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09
vue-loader和webpack項(xiàng)目配置及npm錯(cuò)誤問(wèn)題的解決
這篇文章主要介紹了vue-loader和webpack項(xiàng)目配置及npm錯(cuò)誤問(wèn)題的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
Vue單頁(yè)面應(yīng)用中實(shí)現(xiàn)Markdown渲染
這篇文章主要介紹了Vue單頁(yè)面應(yīng)用中如何實(shí)現(xiàn)Markdown渲染,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下2021-02-02
js節(jié)流防抖應(yīng)用場(chǎng)景,以及在vue中節(jié)流防抖的具體實(shí)現(xiàn)操作
這篇文章主要介紹了js節(jié)流防抖應(yīng)用場(chǎng)景,以及在vue中節(jié)流防抖的具體實(shí)現(xiàn)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09
vue項(xiàng)目中axios請(qǐng)求網(wǎng)絡(luò)接口封裝的示例代碼
這篇文章主要介紹了vue項(xiàng)目中axios請(qǐng)求網(wǎng)絡(luò)接口封裝的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
Vue中的v-model綁定修飾符的實(shí)現(xiàn)原理
v-model 是Vue.js中的一個(gè)重要指令,通過(guò)它我們可以輕松實(shí)現(xiàn)數(shù)據(jù)的雙向綁定,本文介紹一些常用的 v-model 綁定修飾符,并解析它們的實(shí)現(xiàn)原理,感興趣的朋友一起看看吧2024-01-01
解決Vue3使用Element-Plus導(dǎo)航刷新后active高亮消失的問(wèn)題
這篇文章主要給大家介紹了如何解決Vue3使用Element-Plus導(dǎo)航刷新后active高亮消失的問(wèn)題,文中有相關(guān)的代碼講解,需要的朋友可以參考下2023-08-08
vue 監(jiān)聽(tīng)某個(gè)div垂直滾動(dòng)條下拉到底部的方法
今天小編就為大家分享一篇vue 監(jiān)聽(tīng)某個(gè)div垂直滾動(dòng)條下拉到底部的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09

