完整示例参考如下:
@Entry @Component struct RichEditorExample { controller: RichEditorController = new RichEditorController(); options: RichEditorOptions = { controller: this.controller }; build() { Row() { Column() { RichEditor(this.options) .onReady(() => { // 组件初始化完成后会触发onReady回调 // 在addTextSpan第一个参数中输入文本值,在第二个参数添加style,style中fontFeature属性为subs this.controller.addTextSpan('下角标效果示例:二氧化碳,CO2\n', { style: { fontSize: 20, fontFeature: '\"subs\"' } }); this.controller.addTextSpan('上角标效果示例:X的平方,X2\n', { style: { fontSize: 20, fontFeature: '\"sups\"' } }); }) .borderWidth(1) .padding(5) .width('100%') } .width('100%') } } }