vue.js組件化使用百度富文本編輯器(一)


注意:

本文采用的編輯器為:idea

1.下載百度富文本編輯器,地址:https://ueditor.baidu.com/website/download.html#ueditor

2.加入到static文件夾下,如圖:

3.在main.js中引入js。

注意:一定要修改ueditor.config.js中的路徑

window.UEDITOR_HOME_URL = "./static/ueditor/"

 

 
        

4.編寫vue組件:

<template>
<div>
<script id="editor" type="text/plain"></script>
</div>
</template>
<script>
export default {
name: 'UE',
data () {
return {
editor: null
}
},
props: {
defaultMsg: {
type: String
},
config: {
type: Object
}
},
mounted() {
const _this = this;
this.editor = UE.getEditor('editor', this.config); // 初始化UE
this.editor.addListener("ready", function () {
_this.editor.setContent(_this.defaultMsg); // 確保UE加載完成后,放入內容。
});
},
methods: {
getUEContent() { // 獲取內容方法
return this.editor.getContent()
}
},
destroyed() {
this.editor.destroy();
}
}
</script>

5.編寫測試使用的Vue界面:
<template>
<div>
<navigation></navigation>
<div style="width: 50%;padding-left: 25%;" >
<!--<el-input type="textarea" v-model="form.desc" placeholder="說點什么吧"></el-input>-->
<div class="components-container">
<el-button @click="getUEContent()" type="primary" style="padding: 10px;margin: 10px;">獲取內容</el-button>
<div class="editor-container">
<ueditor :defaultMsg=defaultMsg :config=config ref="ue"></ueditor>
</div>
</div>
</div>
</div>
</template>

<script>
//采用局部引用的方式注冊組件
import ueditor from '@/components/Ueditor';
export default {
name: "PublishPage",
data() {
return {
defaultMsg: '說點什么吧',
config: {
initialFrameWidth: null,
initialFrameHeight: 350
}
}
},
components: {
ueditor
},
methods: {
getUEContent() {
let content = this.$refs.ue.getUEContent();
this.$notify({
title: '獲取成功,可在控制台查看!',
message: content,
type: 'success'
});
console.log(content)
}
}
}
</script>

<style scoped>

</style>

6.編寫路由

7.運行項目

npm run dev

8.效果展示

注:

1.編寫的文本和媒體文件發送到服務端請看下一篇介紹。

2.這是筆者學習記錄的過程,如果有錯誤,敬請指正,不喜勿噴,謝謝。

 

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM