Vue+Element使用富文本編輯器的示例代碼
富文本編輯器在任何項(xiàng)目中都會用到,在Element中我們推薦vue-quill-editor組件,現(xiàn)在我就把它提供給大家,希望對大家有用。具體截圖如下:

安裝編輯器組件
具體方法:npm install vue-quill-editor --save
編寫組件
首先我們在components文件夾里創(chuàng)建ue.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加載完成后,放入內(nèi)容。
});
},
methods: {
getUEContent() { // 獲取內(nèi)容方法
return this.editor.getContent()
}
},
destroyed() {
this.editor.destroy();
}
}
</script>
在頁面中使用
下面是使用代碼
<template>
<div>
<el-row class="warp">
<el-col :span="24" class="warp-breadcrum">
<el-breadcrumb separator=">">
<el-breadcrumb-item :to="{path:'/home'}"><b>首頁</b></el-breadcrumb-item>
<el-breadcrumb-item :to="{path: '/aboutus/aboutlist'}">關(guān)于我們</el-breadcrumb-item>
<el-breadcrumb-item>添加關(guān)于我們</el-breadcrumb-item>
</el-breadcrumb>
</el-col>
<!--
Form 組件提供了表單驗(yàn)證的功能,只需要通過 rule 屬性傳入約定的驗(yàn)證規(guī)則,并 Form-Item 的 prop 屬性設(shè)置為需校驗(yàn)的字段名即可。具體可以參考官網(wǎng):http://element.eleme.io/#/zh-CN/component/form
-->
<el-col :span="24" class="warp-main">
<el-form ref="infoForm" :model="infoForm" :rules="rules" label-width="120px">
<el-form-item label="標(biāo)題" prop="a_title">
<el-input v-model="infoForm.a_title"></el-input>
</el-form-item>
<el-form-item label="來源" prop="a_source">
<el-input v-model="infoForm.a_source"></el-input>
</el-form-item>
<!--使用編輯器
-->
<el-form-item label="詳細(xì)">
<div class="edit_container">
<quill-editor v-model="infoForm.a_content"
ref="myQuillEditor"
class="editer"
:options="editorOption" @ready="onEditorReady($event)">
</quill-editor>
</div>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">確認(rèn)提交</el-button>
</el-form-item>
</el-form>
</el-col>
</el-row>
</div>
</template>
<script>
import { quillEditor } from 'vue-quill-editor' //調(diào)用編輯器
export default {
data() {
return {
infoForm: {
a_title: '',
a_source: '',
a_content:'',
editorOption: {}
},
//表單驗(yàn)證
rules: {
a_title: [
{required: true, message: '請輸入標(biāo)題', trigger: 'blur'}
],
a_content: [
{required: true, message: '請輸入詳細(xì)內(nèi)容', trigger: 'blur'}
]
},
}
},
computed: {
editor() {
return this.$refs.myQuillEditor.quill
}
},
mounted() {
//初始化
},
methods: {
onEditorReady(editor) {
},
onSubmit() {
//提交
//this.$refs.infoForm.validate,這是表單驗(yàn)證
this.$refs.infoForm.validate((valid) => {
if(valid) {
this.$post('m/add/about/us',this.infoForm).then(res => {
if(res.errCode == 200) {
this.$message({
message: res.errMsg,
type: 'success'
});
this.$router.push('/aboutus/aboutlist');
} else {
this.$message({
message: res.errMsg,
type:'error'
});
}
});
}
});
}
},
components: {
//使用編輯器
quillEditor
}
}
</script>
以上就是全部代碼,謝謝大家,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用自動導(dǎo)入后eslint報(bào)錯(cuò)eslint9的問題及解決方法
本文介紹了使用`pnpm create vue@latest`創(chuàng)建Vue應(yīng)用時(shí),如何配置ESLint和Prettier,包括解決兩者沖突以及自動導(dǎo)入后Eslint報(bào)錯(cuò)的問題,感興趣的朋友一起看看吧2025-03-03
Vue ECharts簡易實(shí)現(xiàn)雷達(dá)圖
這篇文章主要介紹了基于Vue ECharts簡易實(shí)現(xiàn)雷達(dá)圖,本文通過實(shí)例代碼圖文相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-12-12
Vue.js bootstrap前端實(shí)現(xiàn)分頁和排序
這篇文章主要為大家詳細(xì)介紹了Vue.js結(jié)合bootstrap前端實(shí)現(xiàn)分頁和排序效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03
vue?element?ui?Select選擇器如何設(shè)置默認(rèn)狀態(tài)
這篇文章主要介紹了vue?element?ui?Select選擇器如何設(shè)置默認(rèn)狀態(tài)問題,具有很好的參考價(jià)值,希望對大家有所幫助,2023-10-10
壓縮Vue.js打包后的體積方法總結(jié)(Vue.js打包后體積過大問題)
大家都知道,Vuejs的 CLI工具 是基于 webpack 來實(shí)現(xiàn)的,所以在項(xiàng)目打包后,會生成的文件會很大。 主要原因是 webpack 將我們所有文件都打包成一個(gè)js文件,即使再小的項(xiàng)目,打包之后文件都會變得很大。 下面講講最近我遇到的相同問題。2020-02-02
Vue Element前端應(yīng)用開發(fā)之菜單資源管理
在權(quán)限管理系統(tǒng)中,菜單也屬于權(quán)限控制的一個(gè)資源,屬于角色控制的一環(huán)。不同角色用戶,登錄系統(tǒng)后,出現(xiàn)的系統(tǒng)菜單是不同的。菜單結(jié)合路由集合,實(shí)現(xiàn)可訪問路由的過濾,也就實(shí)現(xiàn)了對應(yīng)角色菜單的展示和可訪問路由的控制。2021-05-05
手寫Vue內(nèi)置組件component的實(shí)現(xiàn)示例
本文主要介紹了手寫Vue內(nèi)置組件component的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07
解決vue this.$forceUpdate() 處理頁面刷新問題(v-for循環(huán)值刷新等)
這篇文章主要介紹了解決vue this.$forceUpdate() 處理頁面刷新問題(v-for循環(huán)值刷新等),解決方法是使用this.$forceUpdate()強(qiáng)制刷新,文章給大家分享了代碼案例,需要的朋友參考下吧2018-07-07

