HarmonyOS RichText组件如何处理返回的富文本适配手机宽度自动换行?

如题:HarmonyOS RichText组件如何处理返回的富文本适配手机宽度自动换行?

阅读 530
1 个回答

推荐使用web组件,参考代码:

import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct DetailsPage {
  @State myHtmlCenter: string =”后端返回的数据”
  @State myHtmlStart: string = `
<html >
<body>
`
  @State myHtmlEnd: string = `
</body>
</html>
`
  WebviewController: webview.WebviewController = new webview.WebviewController();
  build() {
    Column() {
      Scroll() {
        Web({
          src: '', controller: this.WebviewController, renderMode: RenderMode.SYNC_RENDER
        })
          .width('100%')
          .domStorageAccess(true)
          .onAppear(() => {
            this.WebviewController.loadData(`${this.myHtmlStart}${this.myHtmlCenter} ${this.myHtmlEnd}`, "text/html", "UTF-8",'','');
          })
          .hitTestBehavior(HitTestMode.None)
          .layoutMode(WebLayoutMode.FIT_CONTENT)
          .nestedScroll({
            scrollForward: NestedScrollMode.SELF_ONLY, scrollBackward: NestedScrollMode.SELF_ONLY
          })
      }.width('100%').height('85%').align(Alignment.Top)
    }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进