官网介绍:wangEditor - 轻量级 web 富文本编辑器
使用步骤:
第一步:安装富文本编辑器
npm install wangeditor
第二步:在需要使用的组件中引入编辑器
import E from "wangeditor"
第三步:记住,在mounted()中使用,因为需要操作dom
//初始化
this.editor = new E('#editor')
this.editor.create()
第四步:获取输入框的内容:
console.log(this.editor.txt.html());
整体代码:
<template>
<div>
<div id="editor">
</div>
<button @click="add()">提交</button>
</div>
</template>
<script>
import E from "wangeditor"
export default {
data() {
return {
editor:''
}
},
mounted(){
this.editor = new E('#editor')
this.editor.create()
},
methods: {
add(){
console.log(this.editor.txt.html());
}
},
}
</script>