1、npm安装
npm install @wangeditor/editor --save
npm install @wangeditor/editor-for-vue@next --save
2、创建wangeditor的组件
<template>
<div style="border: 1px solid #ccc">
<Toolbar :editor="editorRef" :defaultConfig="toolbarConfig" />
<Editor v-model="valueHtml" :defaultConfig="editorConfig" @onCreated="handleEditorCreated" />
</div>
</template>
<script lang="ts">
import '@wangeditor/editor/dist/css/style.css' // 引入 css
import {
Editor, Toolbar } from '@wangeditor/editor-for-vue'
import {
ref, shallowRef, watchEffect } from 'vue'
export default {
components: {
Editor,
Toolbar
},
props: {
value: String
},
emits: ['update:value'],
setup(props, {
emit }) {
// 编辑器实例,必须用 shallowRef
const editorRef = shallowRef(null)
// 内容 HTML
const valueHtml = ref(props.value || '')
//配置功能栏
let toolbarConfig = {
toolbarKeys: [
'headerSelect'