小程序开放平台

文档中心
基础
界面
网络
数据缓存
媒体
图片
地图
视频
富文本
createEditorContext
EditorContext
位置
开放接口
设备
XHSML
性能
文件
数据分析
画布

xhs.createEditorContext

开发
>
JS API
>
媒体
>
富文本
>
createEditorContext
>
更新时间:2025-04-10 19:20:28

创建 editor 上下文 EditorContext 对象。建议使用 xhs.createEditorContext 获取 context 对象。

参数

string id

editor 组件的 id

返回值

EditorContext

实例代码

// 示例代码:创建 EditorContext 对象
function createEditorContext(editorId) {
  // 使用 xhs.createEditorContext 获取 EditorContext 对象
  const editorContext = xhs.createEditorContext(editorId);
  return editorContext;
}

// 调用示例
const editorId = 'myEditor'; // 替换为实际的 editor 组件 id
const editorContext = createEditorContext(editorId);

// 使用 EditorContext 示例
editorContext.insertText({
  text: 'Hello, 小红书!',
  success: () => {
    console.log('文本插入成功');
  },
  fail: (err) => {
    console.error('文本插入失败:', err);
  },
});
该文档是否对您有帮助?