本文整理自网络,侵删。
EditorContext
EditorContext 实例,可通过 wx.createSelectorQuery 获取。
EditorContext 通过 id 跟一个 editor 组件绑定,操作对应的 editor 组件。
方法:
EditorContext.blur(Object object)
基础库 2.8.3 开始支持,低版本需做兼容处理。编辑器失焦,同时收起键盘。
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
EditorContext.clear(Object object)
基础库 2.7.0 开始支持,低版本需做兼容处理。
清空编辑器内容
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
EditorContext.format(string name, string value)
基础库 2.7.0 开始支持,低版本需做兼容处理。修改样式
参数
string name
属性
string value
值
支持设置的样式列表
name | value | verson |
---|---|---|
bold | 2.7.0 | |
italic | 2.7.0 | |
underline | 2.7.0 | |
strike | 2.7.0 | |
ins | 2.7.0 | |
script | sub / super | 2.7.0 |
header | H1 / H2 / h3 / H4 / h5 / H6 | 2.7.0 |
align | left / center / right / justify | 2.7.0 |
direction | rtl | 2.7.0 |
indent | -1 / +1 | 2.7.0 |
list | ordered / bullet / check | 2.7.0 |
color | hex color | 2.7.0 |
backgroundColor | hex color | 2.7.0 |
margin/marginTop/marginBottom/marginLeft/marginRight | css style | 2.7.0 |
padding/paddingTop/paddingBottom/paddingLeft/paddingRight | css style | 2.7.0 |
font/fontSize/fontStyle/fontVariant/fontWeight/fontFamily | css style | 2.7.0 |
lineHeight | css style | 2.7.0 |
letterSpacing | css style | 2.7.0 |
textDecoration | css style | 2.7.0 |
textIndent | css style | 2.8.0 |
wordWrap | css style | 2.10.2 |
wordBreak | css style | 2.10.2 |
whiteSpace | css style | 2.10.2 |
对已经应用样式的选区设置会取消样式。css style 表示 css 中规定的允许值。
EditorContext.getContents(Object object)
基础库 2.7.0 开始支持,低版本需做兼容处理。获取编辑器内容
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数
参数
Object res
属性 | 类型 | 说明 |
---|---|---|
html | string | 带标签的HTML内容 |
text | string | 纯文本内容 |
delta | Object | 表示内容的delta对象 |
EditorContext.getSelectionText(Object object)
基础库 2.10.2 开始支持,低版本需做兼容处理。获取编辑器已选区域内的纯文本内容。当编辑器失焦或未选中一段区间时,返回内容为空。
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数
参数
Object res
属性 | 类型 | 说明 |
---|---|---|
text | string | 纯文本内容 |
EditorContext.insertDivider(Object object)
基础库 2.7.0 开始支持,低版本需做兼容处理。插入分割线
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
EditorContext.insertImage(Object object)
基础库 2.7.0 开始支持,低版本需做兼容处理。插入图片。
相关阅读 >>
微信小程序云开发服务端存储api 用云文件 id 换取真实链接
更多相关阅读请进入《微信小程序》频道 >>
Vue.js 设计与实现 基于Vue.js 3 深入解析Vue.js 设计细节
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者