HarmonyOS 鸿蒙Next:@Entry decorated components and @Preview decorated root components should not contain decorators forbidding local initialization

HarmonyOS 鸿蒙Next:@Entry decorated components and @Preview decorated root components should not contain decorators forbidding local initialization 创建组件之后,不同在编辑器中预览

cke_1515.png

cke_2605.png

import { router } from '@kit.ArkUI'

[@Entry](/user/Entry)
@Component
struct AddForumPage {
  build() {
    Column() {
      RelativeContainer() {
        Image($r("app.media.icon_nav_back"))
          .width(40)
          .height(40)
          .padding(10)
          .onClick(() => {
            router.back()
          })
          .id("back")
          .alignRules({
            left: { anchor: "__container__", align: HorizontalAlign.Start },
            center: { anchor: "__container__", align: VerticalAlign.Center }
          })
        Text("发帖")
          .fontSize(18)
          .fontColor($r('app.color.color_333333'))
          .layoutWeight(1)
          .fontWeight(FontWeight.Bold)
          .maxLines(1)
          .ellipsisMode(EllipsisMode.CENTER)
          .textOverflow({ overflow: TextOverflow.Ellipsis })
          .textAlign(TextAlign.Center)
          .id("title")
          .alignRules({
            middle: { anchor: "__container__", align: HorizontalAlign.Center },
            center: { anchor: "__container__", align: VerticalAlign.Center }
          })
          .textAlign(TextAlign.Center)
        Text("发帖")
          .alignRules({
            right: { anchor: "__container__", align: HorizontalAlign.End },
            center: { anchor: "__container__", align: VerticalAlign.Center }
          })
          .fontColor($r("app.color.color_19af87"))
          .padding(10)
          .onClick(() => {
          })
      }
      .height(50)

      Row() {
        Text("*")
          .fontColor($r("app.color.color_cb3232"))
      }
    }
  }
}

更多关于HarmonyOS 鸿蒙Next:@Entry decorated components and @Preview decorated root components should not contain decorators forbidding local initialization的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

你贴的代码好像不是报错的代码?意思是说@Entry类型的page,不能有@Prop@Link等依赖父组件状态的

更多关于HarmonyOS 鸿蒙Next:@Entry decorated components and @Preview decorated root components should not contain decorators forbidding local initialization的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


针对帖子标题“HarmonyOS 鸿蒙Next:@Entry decorated components and @Preview decorated root components should not contain decorators forbidding local initialization”的问题,以下是专业回答:

在HarmonyOS鸿蒙Next的开发中,遇到[@Entry](/user/Entry)装饰的组件和[@Preview](/user/Preview)装饰的根组件不能包含禁止本地初始化的装饰器的问题,这通常意味着你的组件或预览根组件中使用了某些装饰器,这些装饰器的规则与鸿蒙系统的组件初始化机制相冲突。

具体来说,[@Entry](/user/Entry)[@Preview](/user/Preview)装饰的组件需要能够在本地进行初始化,以便正确地渲染和预览。如果使用了禁止本地初始化的装饰器,如某些可能限制组件状态或行为的装饰器,就会导致此错误。

为了解决这个问题,你需要检查并移除或替换那些禁止本地初始化的装饰器。确保你的组件和预览根组件能够按照鸿蒙系统的要求,在本地进行正确的初始化和渲染。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部