uni.createEditorContextAsync(options)
创建并返回 editor 上下文 editorContext 对象
本API是 editor组件 的上下文对象。
createEditorContextAsync 兼容性
| Web | 微信小程序 | Android | Android(Vapor) | iOS | iOS(Vapor) | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | x | 5.08 | x | 5.08 | 5.08 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| options | CreateEditorContextAsyncOptions | 是 | | | |
|
EditorContext 的方法
format
修改样式
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| name | string | 是 | | | |
| value | string | number | 否 | | | |
insertDivider(options ?: UniEditorElementOptions | null) : void
insertDivider
插入分割线
insertDivider 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| options | UniEditorElementOptions | 否 | | | |
|
UniEditorElementOptionsSuccessRes 的属性值
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
| errMsg | string | 是 | | | |
UniEditorElementOptionsFailRes 的属性值
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
| errMsg | string | 是 | | | |
UniEditorElementOptionsCompleteRes 的属性值
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
| errMsg | string | 是 | | | |
insertImage(options ?: UniEditorElementInsertImageOptions | null) : void
insertImage
插入图片
insertImage 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| options | UniEditorElementInsertImageOptions | 否 | | | |
|
insertText(options ?: UniEditorElementInsertTextOptions | null) : void
insertText
覆盖当前选区,设置一段文本
insertText 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| options | UniEditorElementInsertTextOptions | 否 | | | |
|
insertLink(options ?: UniEditorElementInsertLinkOptions | null) : void
insertLink
插入链接
insertLink 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| options | UniEditorElementInsertLinkOptions | 否 | | | |
|
insertMention(options ?: UniEditorElementInsertMentionOptions | null) : void
insertMention
插入可整块删除的提及,提及文本默认为
insertMention 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.11 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| options | UniEditorElementInsertMentionOptions | 否 | | | |
|
setContents(options ?: UniEditorElementSetContentsOptions | null) : void
setContents
初始化编辑器内容,html和delta同时存在时仅delta生效
setContents 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| options | UniEditorElementSetContentsOptions | 否 | | | |
|
getContents(options ?: UniEditorElementGetContentsOptions | null) : void
getContents
获取编辑器内容
getContents 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| options | UniEditorElementGetContentsOptions | 否 | | | |
|
UniEditorElementGetContentsOptionsRes 的属性值
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
| errMsg | string | 是 | | | |
| delta | any | 是 | | | |
| html | string | 是 | | | |
| text | string | 是 | | | |
clear(options ?: UniEditorElementOptions | null) : void
clear
清空编辑器内容
clear 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
removeFormat
清除当前选区的样式
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
undo(options ?: UniEditorElementOptions | null) : void
undo
撤销
undo 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
redo(options ?: UniEditorElementOptions | null) : void
redo
恢复
redo 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
getSelectionText(options ?: UniEditorElementGetSelectionTextOptions | null) : void
getSelectionText
获取编辑器已选区域内的纯文本内容。当编辑器失焦或未选中一段区间时,返回内容为空。
getSelectionText 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
| options | UniEditorElementGetSelectionTextOptions | 否 | | | |
|
UniEditorElementGetSelectionTextOptionsRes 的属性值
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
| errMsg | string | 是 | | | |
| text | string | 是 | | | |
scrollIntoView
使得编辑器光标处滚动到窗口可视区域内。
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
blur(options ?: UniEditorElementOptions | null) : void
blur
编辑器失焦,同时收起键盘
blur 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS | HarmonyOS(Vapor) |
| 5.08 | 5.08 | 5.08 | 5.08 | √ | 5.08 | 5.08 |
参数
参见
通用类型
GeneralCallbackResult
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
| errMsg | string | 是 | | | 错误信息 |