最近在做后臺(tái)管理系統(tǒng)的時(shí)候遇到要使用富文本編輯器。最后選擇了ueditor,我的項(xiàng)目使用 vue+vuex+vue-router+webpack+elementUI的方案完成框架的搭建,
1、下載UEditor官網(wǎng)最新的jsp版本的包,下載完成解壓之后得到一個(gè)utf8-jsp的文件夾,里面包含的內(nèi)容如下:
2、將這個(gè)文件夾改名為ueditor,并且移入自己項(xiàng)目中的static文件夾下,修改ueditor.config.js文件夾中的內(nèi)容,如下圖:
3、編寫(xiě)子組件
<template> <div :id="id" type="text/plain"></div> </template> <script> import '../../../static/ueditor/ueditor.config.js' import '../../../static/ueditor/ueditor.all.min.js' import '../../../static/ueditor/lang/zh-cn/zh-cn.js' import '../../../static/ueditor/ueditor.parse.min.js' export default { name: 'UE', data() { return { editor: null } }, props: { defaultMsg: { type: String, default: '請(qǐng)輸入內(nèi)容' }, config: { type: Object }, id: { type: String, default: `ue${Math.random(0, 100)}` } }, mounted() { this.$nextTick(() => { this.editor = UE.getEditor(this.id, this.config); // 初始化UE this.editor.addListener("ready", () => { this.editor.execCommand('insertHtml', this.defaultMsg); this.editor.focus() // 確保UE加載完成后,放入內(nèi)容。 }) }) }, methods: { getUEContent() { // 獲取內(nèi)容方法 return this.editor.getContent() }, clearContent() { // 清空編輯器內(nèi)容 return this.editor.execCommand('cleardoc'); }, }, beforeDestroy() { // 組件銷毀的時(shí)候,要銷毀 UEditor 實(shí)例 if (this.editor !== null && this.editor.destroy) { this.editor.destroy(); } } } </script> <style scoped></style>
4、在父組件中使用
<UE :config="configEditor" :id="ue1" ref="ue" :defaultMsg="val"></UE>
5、弄好之后,上傳圖片會(huì)提示后端配置項(xiàng)http錯(cuò)誤,文件上傳會(huì)提示上傳錯(cuò)誤。這里提別申明一點(diǎn),ueditor在前端配置好后,需要與后端部分配合進(jìn)行,然后將配置ueditor.config.js 里的serverUrl的前綴改陳你自己的后端訪問(wèn)的請(qǐng)求路徑地址
serverUrl: "統(tǒng)一請(qǐng)求地址"
總結(jié)
以上所述是小編給大家介紹的vue中使用ueditor富文本編輯器,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com