1.vue中安装wangEditor
使用npm安装:npm install wangeditor --save
2.创建公共组件
在components中创建editor文件
组件内容为:
<template lang="html">
<div class="editor">
<div ref="toolbar" class="toolbar">
</div>
<div ref="editor" class="text">
</div>
</div>
</template>
<script>
import E from 'wangeditor'
export default {
name: 'Editorbar',
data () {
return {
editor: null,
info_: null
}
},
model: {
prop: 'value',
event: 'change'
},
props: {
value: {
type: String,
default: ''
},
isClear: {
type: Boolean,
default: false
}
},
watch: {
isClear (val) {
// 触发清除文本域内容
if (val) {
this.editor.txt.clear()
this.info_ = null
}
},
value (val) {
// 使用 v-model 时,设置初始值
this.editor.txt.html(val)
}
},
mounted () {
th