Skip to content

Editor 富文本编辑器

基于 TinyMCE 5 封装,支持工具栏自定义和图片上传。

基础用法

vue
<template>
  <div>
    <p>{{ content }}</p>
    <div class="btns">
      <ElButton type="primary" @click="setContent">修改content</ElButton>
    </div>
    <MEditor v-model="content" @mouse-down="mouseDown"></MEditor>

    <MMarkdownView :value="readme"></MMarkdownView>
  </div>
</template>

<script setup lang="ts">
import readme from '@/components/editor/README.md?raw'
import { ref } from 'vue'

const content = ref('123')
const setContent = () => {
  content.value += 'abc'
}

const mouseDown = () => {
  console.log('mouseDown')
}
</script>

<style lang="scss" scoped>
.btns {
  margin-bottom: 20px;
}
</style>

API

Editor 属性

属性名说明类型默认值
optionsTinyMCE init 配置Partial<RawEditorSettings>{}
modelValuev-model 编辑器内容string''
disabled禁用编辑器booleanfalse
toolbar工具栏按钮string[]内置默认
plugins插件列表string[]内置默认
height编辑器高度number | string400
upload图片上传接口Function | falseuploadCommon
uploadFileKeyFormData 的 keystring'file'

Editor 事件

事件名说明类型
change内容变化时触发(content: string) => void
update:modelValue内容变化时触发(content: string) => void
initedTinyMCE 初始化完成(editor: Editor) => void
init-errorTinyMCE 初始化错误(err: any) => void

$attrs

Editor 的 $attrs会透传给 TinyMCE 的事件系统(如onActivateonAddUndo 等)。

基于 MIT 许可发布