Skip to content

API 说明

Props

名称类型默认值说明
modelValuestring""编辑器 HTML 内容
placeholderstring"开始输入内容..."空内容提示
editablebooleantrue是否可编辑
minHeightnumber | string280编辑区域最小高度
locale"zh-CN" | "en-US" | string"zh-CN"工具栏文案语言
messagesRecord<string, string>{}自定义文案,覆盖内置语言包
toolbarstring[] | string[][]见默认配置工具栏按钮配置
toolbarPermissionsRecord<string, boolean | "hidden" | "disabled">{}按钮权限控制,false/hidden 为隐藏,disabled 为展示但禁用
toolbarTheme"light" | "slate" | "sand" | Record<string, string>"light"工具栏主题预设,或传入主题变量对象
uploadImage(file: File, context: { onProgress: (value: number) => void }) => Promise<string | { url: string }>null图片上传适配器,支持进度上报
sanitizebooleantrue是否启用内容清洗
sanitizeOptionsobject内置安全策略DOMPurify 全局配置
pasteWhitelistTagsstring[]内置白名单粘贴时允许保留的标签
pasteWhitelistAttrsstring[]内置白名单粘贴时允许保留的属性
pasteSanitizeOptionsobject{}粘贴专用 DOMPurify 配置,会与白名单配置合并
linkTargetstring"_blank"链接 target
linkRelstring"noopener noreferrer nofollow"链接 rel
allowedLinkProtocolsstring[]["http", "https", "mailto", "tel"]允许的链接协议
linkDomainWhiteliststring[][]允许的链接域名白名单,支持匹配子域名
validateLink(payload) => boolean | stringnull自定义链接校验,返回 false 或错误文案时阻止写入

默认 toolbar

js
[
  ["blockType"],
  ["bold", "italic", "underline", "strike", "highlight"],
  ["bulletList", "orderedList", "taskList", "horizontalRule"],
  ["table"],
  ["alignLeft", "alignCenter", "alignRight", "alignJustify"],
  ["link", "image"],
  ["clearFormatting", "undo", "redo"],
]

新增按钮关键字:

  • taskList
  • table

Events

事件参数说明
update:modelValue(html: string)内容更新时触发
focus(event: FocusEvent)编辑区获得焦点
blur(event: FocusEvent)编辑区失去焦点
ready(editor: Editor)编辑器实例就绪
image-upload-start(file: File)图片上传开始
image-upload-progress(progress: number)图片上传进度变化
image-upload-success(src: string)图片上传成功并插入编辑器
image-upload-error(error: unknown)图片上传失败

Expose

方法返回值说明
getHTML()string获取 HTML
getJSON()JSON获取 ProseMirror JSON
setHTML(content)void设置 HTML
clear()void清空内容
focus()void聚焦编辑器
retryLastImageUpload()Promise<void>重新执行最近一次失败的图片上传

主题对象字段

toolbarTheme 传入对象时,可以按需覆盖以下字段:

js
{
  borderColor: "#dcdfe6",
  toolbarBackground: "#f8fafc",
  toolbarBorder: "#ebeef5",
  groupBorder: "#e5e7eb",
  panelBackground: "#f8fafc",
  buttonBackground: "#ffffff",
  buttonBorder: "#d1d5db",
  buttonText: "#1f2937",
  buttonHoverBorder: "#9ca3af",
  buttonActiveBackground: "#eff6ff",
  buttonActiveBorder: "#2563eb",
  buttonActiveText: "#1d4ed8",
  primaryBackground: "#2563eb",
  primaryText: "#ffffff",
}