引入项目
npm install wangeditor -S
代码使用
HTML
<div ref="editorElem"></div>
JS import
import E from 'wangeditor'
mounted中初始化
data () {
return {
editor: null
}
}
mounted () {
this.editor = new E(this.$refs.editorElem)
// 编辑器的事件,每次改变会获取其html内容
this.editor.config.onchange = (html) => {
console.log(html)
}
this.editor.create()
},
部分使用方法
// 设置其中内容
this.editor.txt.html('<p>12312321321321321</p>')
// 获取其中内容
this.editor.txt.html()