挂载与生命周期
createClassicEditor(host, options) 接受 textarea 或 HTMLElement,并返回 Promise。等待创建结束后再读取实例。textarea 适合原生表单;普通元素由应用负责保存。
同一宿主不能重复挂载。动态表单或弹窗应在移除元素之前等待 destroy()。setData() 接收已存储 HTML,getData() 返回规范内容,不要读取编辑区域 DOM 来保存。
可运行代码
ts
export async function withHost(host: HTMLElement) {
const editor = await createClassicEditor(host, { data: '<p>Hello</p>' });
editor.setData('<p>Updated</p>');
const html = editor.getData();
editor.setReadonly(true);
await editor.destroy(); // Before removing the host element.
return html;
}此代码使用发布版类型检查;完整导入说明见入口与类型。