HarmonyOS 鸿蒙Next:Assigning the 'REGULAR' decorated attribute 'item' to the '@Prop' decorated attribute 'item' is not allowed. <etsLint>

HarmonyOS 鸿蒙Next:Assigning the ‘REGULAR’ decorated attribute ‘item’ to the ‘@Prop’ decorated attribute ‘item’ is not allowed. <etsLint>

Assigning the ‘REGULAR’ decorated attribute ‘item’ to the ‘@Prop’ decorated attribute ‘item’ is not allowed.

cke_295.png


更多关于HarmonyOS 鸿蒙Next:Assigning the 'REGULAR' decorated attribute 'item' to the '@Prop' decorated attribute 'item' is not allowed. <etsLint>的实战教程也可以访问 https://www.itying.com/category-93-b0.html

14 回复

看下ChildItem里的代码咋写的

更多关于HarmonyOS 鸿蒙Next:Assigning the 'REGULAR' decorated attribute 'item' to the '@Prop' decorated attribute 'item' is not allowed. <etsLint>的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


图片

题主的eslint警告错误的意思是应该要把类型确定的属性传递给子组件,我猜测是类型推导有问题,所以当我们传递给子组件属性的时候,确定一下item的类型。期待后续版本修复吧

厉害

遍历出的item做下处理,item as string 就好了

亲测有效,

亲测有效,

有效+1

这个方案可以,

基本信息

  • 项目名称: ABC项目
  • 负责人: 张三
  • 状态: 进行中

详细信息

  • 开始时间: 2023-01-01
  • 结束时间: 2023-12-31

备注

  • 需要每周汇报进度

我的理解是,@Prop只能传父组件上@State装饰的值

在下认为这个理解是对的,

@Observed@ObjectLink,同样的代码,在api9无法双向绑定数据更新,api10可以, 这俩差异是啥那?bug么

cke_195.png

反正断言就行,我写个非空相对简单些,不用管类型

这样去写 ChildItem(`{item:this.simpleList[index]}`) 就可以了

请问解决了吗?

在HarmonyOS鸿蒙Next开发中,@Prop装饰器用于定义组件的属性,并且该属性是单向绑定的,意味着它只能从父组件传递到子组件。@Prop装饰的属性不允许直接赋值,因为它们的设计目的是接收父组件传递的数据,而不是在子组件内部进行修改。

REGULAR装饰属性指的是普通的属性,没有使用任何装饰器(如@Prop@State等)。当你尝试将一个普通的属性(item)赋值给@Prop装饰的属性时,会触发etsLint的警告或错误,因为这在鸿蒙的框架设计中被认为是不允许的操作。

具体来说,@Prop装饰的属性应该是只读的,因此在子组件中不能直接对其进行赋值操作。如果你需要在子组件中修改该属性,应该使用@State或其他适合的装饰器。

总结:在鸿蒙Next中,@Prop装饰的属性不能直接接收普通属性的赋值,因为它们的设计是单向绑定的,只能从父组件传递数据。

回到顶部