在vue3下使用v5版本
获取所有key的方法
editorRef.value.getAllMenuKeys()
DOM
<Toolbar
style="border-bottom: 1px solid #ccc"
:editor="editorRef"
:defaultConfig="toolbarConfig"
:mode="mode"
/>
<Editor
style="height: 500px; overflow-y: hidden"
v-model="valueHtml"
:defaultConfig="editorConfig"
:mode="mode"
@onCreated="handleCreated"
/>
<script setup lang="ts">
import '@wangeditor/editor/dist/css/style.css'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import { ref, shallowRef } from 'vue'
import { DomEditor } from '@wangeditor/editor'
const editorRef = shallowRef()
const valueHtml = ref('<p>hello</p>')
const toolbarConfig = {
toolbarKeys: [
'fontSize',
'bold',
'italic',
'underline',
'|',
'color',
'bgColor',
'|',
'justifyLeft',
'justifyRight',
'justifyCenter',
]
}
const editorConfig = { placeholder: '请输入内容...' }
const mode = ref('default')
const handleCreated = (editor) => {
editorRef.value = editor
}
const onToolbarConfig = () => {
console.log(editorRef.value.getAllMenuKeys())
}
</script>