手上有泥,心中有诗
137 字
1 分钟
vue3富文本编辑组件
下载:
npm install @wangeditor/editor @wangeditor/editor-for-vue@next
使用:
<template> <div class="tool-bar"> <!-- 工具栏 --> <Toolbar class="tool-style" :editor="editorRef" :defaultConfig="toolbarConfig" /> <!-- 编辑器 --> <Editor class="content" v-model="valueHtml" :defaultConfig="editorConfig" @onCreated="handleCreated" /> </div></template>
<script setup>import { onBeforeUnmount, ref, shallowRef} from 'vue'import '@wangeditor/editor/dist/css/style.css'import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
const editorRef = shallowRef()const toolbarConfig= ref()// 内容 HTMLconst valueHtml = ref('<p></p>')
// 编辑器配置const editorConfig = { placeholder: '请输入内容...', MENU_CONF: { /* 菜单配置,下文解释 */ }}
const handleCreated = (editor) => { editorRef.value = editor // 记录 editor 实例,重要!}
// 组件销毁时,及时销毁编辑器onBeforeUnmount(() => { const editor = editorRef.value if (editor == null) return editor.destroy()})</script>