最近做项目遇到一个需求,富文本编辑器,一个工具栏对应三个编辑区,如下图所示:
通过wangEditor封装的组件:
wangEditor 的地址: https://www.wangeditor.com/
<template>
<div>
<div v-show="toolbalSshow" :id="toolbalId" class="toolbar"></div>
<div :id="editorId" class="text"></div>
</div>
</template>
<script>
// 引入 wangEditor
import wangEditor from "wangeditor";
export default {
props: {
content: "",
index: Number,
},
model: {
prop: "content",
event: "change",
},
data() {
return {
editor: null,
editorData: "",
editorId: "vue-wangEditor-" + Date.now() + Math.floor(Math.random() * 1000),
toolbalId:
"vue-wangEditor-toolbal-" + Date.now() + Math.floor(Math.random() * 1000),
editorInedx: this.index,
toolbalSshow: false,
editorContent: this.content,
};
},
mounted() {
let this_ = this;
const { $, BtnMenu, DropListMenu, PanelMenu, DropList, Panel, Tooltip } = wangEditor;
// 菜单 key ,各个菜单不能重复
const menuKey = 'menuKey'+Date.now() + Math.floor(Math.random() * 1000);
const editor = new wangEditor(`#${this.toolbalId}`, `#${this.editorId}`);
class OkrMenu extends BtnMenu {
constructor(editor) {
// data-title属性表示当鼠标悬停在该按钮上时提示该按钮的功能简述
const $elem = wangEditor.$(
`<div class="w-e-menu">
<button>插入OKR</button>