Skip to content

Editor 富文本编辑器

💡 组件名:my-editor

富文本编辑器组件,支持本地图片和视频上传

局部导入

ts
import { defineAsyncComponent } from 'vue'
ts
const MyEditor = defineAsyncComponent(() => import('/@/components/my-editor/index.vue'))

基本使用

ts
const formRef = ref()
const editorRef = ref()

const state = reactive({
  form: { content: '' },
})

const testEditorContent = (rule: any, value: any, callback: any) => {
  if (!value) {
    callback()
  }
  if (editorRef.value.isEmpty()) {
    callback(new Error('请输入内容'))
  } else {
    callback()
  }
}

const onValidateContent = () => {
  formRef.value.validateField('content')
}
vue
<el-form-item
  label="内容"
  prop="content"
  :rules="[
    { required: true, message: '请输入内容', trigger: ['blur', 'change'] },
    { validator: testEditorContent, trigger: ['blur', 'change'] },
  ]"
>
  <MyEditor ref="editorRef" v-model:model-value="form.content" @onBlur="onValidateContent" @onChange="onValidateContent">
  </MyEditor>
</el-form-item>

Props

参数说明类型默认值可选值
disable是否禁用Booleanfalse-
placeholder输入框占位文本String请输入内容...-
mode模式Stringdefaultdefault | simple
height高度String310px-
modelValueHTML 内容String--
getText纯文本内容String--