Skip to content

PowerEditor 主编辑器

PowerEditor 是 PowerEditor3 的核心富文本编辑器组件,基于 Vue 3、Tiptap 与 VFluent3 封装。它提供开箱即用的工具栏、主题切换、图片预览、Markdown 互转、只读展示与插槽扩展能力,适合在业务系统中快速接入可编辑内容区域。

基础用法

vue
<template>
    <power-editor
        v-model="content"
        theme="light"
        placeholder="Write something..."
        @change="handleChange"
        @save-html="handleSaveHtml"
        @save-json="handleSaveJson"
    />
</template>

Props

属性类型必填默认值说明
modelValuestring<p>I'm running PowerEditor with Vue.js.</p>编辑器内容,支持纯文本与 HTML。
editablebooleantrue是否允许编辑。设为 false 时进入只读模式。
placeholderstringWrite something...编辑器占位文案。
disabledPlaceholderbooleanfalse是否禁用占位文案。
contentMaxWidthnumber900正文内容最大显示宽度,单位为 px
editorBackgroundstring-编辑器内部背景色。
editorOutSideBackgroundstring-编辑器外部背景色。
mobileDisplayWidthnumber768小于该宽度时使用移动端布局。
showToolBarbooleantrue是否显示工具栏。
toolbarHeightnumber70工具栏高度。
toolbarBackgroundstring-工具栏背景色。
toolbarBorderRadiusnumber8工具栏圆角。
editablePaddingTopnumber-可编辑模式下的顶部内边距;未传入时使用组件内部默认值。
readOnlyPaddingTopnumber5只读模式下的顶部内边距。
editablePaddingBottomnumber315可编辑模式下的底部内边距。
readOnlyPaddingBottomnumber55只读模式下的底部内边距。
imgInterceptorfunction-图片拦截器,用于接管图片上传、替换与状态展示。详见 ImgInterceptor
mentionItemAttrobject-MentionItem 配置项。详见 MentionItem
starterKitobject() => ({})Tiptap StarterKit 相关自定义配置。
showControlOnReadonlybooleantrue只读模式下是否显示控制栏。
mdDecNodeFuncsPluginsobject-Markdown 解码器自定义节点或标记渲染函数。详见 Markdown Decoder Plugins
mdFlagsobject-Markdown 解码器递归层级标记配置。
foregroundstring#958DF1编辑器强调色。
linkColorstring#958DF1链接颜色。
selectionBackgroundstringrgba(144, 145, 234, 0.3)选中文本背景色。
selectionForegroundstring-选中文本前景色。
tableDragColorstringrgba(144, 145, 234, 0.6)表格拖拽控制块颜色。
codeColorstring-行内代码或代码块颜色。
imgPreviewbooleantrue是否启用图片预览。
imgLazyLoadbooleanfalse是否启用图片懒加载。
theme'light' | 'dark'light编辑器主题。
extensionsarray[]额外的 Tiptap 扩展。
showSavebooleantrue是否显示保存按钮。

Events

事件名参数说明
on-mountededitor编辑器初始化完成后触发,返回当前 Tiptap editor 实例。
container-scrollevent编辑器容器滚动时触发。
changepayload编辑器内容变化时触发。
content-changepayload外部内容变更并同步到编辑器时触发。
save-jsonstring点击保存或调用保存方法后,以 JSON 字符串形式返回内容。
save-htmlstring点击保存或调用保存方法后,以 HTML 字符串形式返回内容。

Methods

通过 ref 可以调用编辑器暴露的方法。

vue
<power-editor ref="editor" />
方法说明
editor.save()保存当前内容,并触发 save-jsonsave-html 事件。
editor.saveMarkdown()将当前编辑器内容转换为 Markdown。
editor.computeMarkdown(markdown)将 Markdown 字符串解析为编辑器内容。
editor.insertMarkdown(markdown)在当前位置插入 Markdown 内容。

Slots

custom-buttons

自定义工具栏按钮。也可以使用 custom-buttons-frontcustom-buttons-[index] 精确控制插入位置,其中 index0 开始,最大为 4;未指定位置时默认插入到工具栏最右侧。

插槽参数:

参数说明
editor当前 Tiptap editor 实例。
defaultClass工具栏按钮的默认样式类名。
vue
<power-editor>
    <template #custom-buttons="{ defaultClass }">
        <fv-button :class="[defaultClass]">Custom</fv-button>
    </template>
</power-editor>

front-content

在正文内容前插入自定义区域,适合展示摘要、头图、说明条或业务自定义头部。

vue
<power-editor>
    <template #front-content>
        <div class="front-content-block">Before editor content</div>
    </template>
</power-editor>

MIT Licensed