HarmonyOS 鸿蒙Next '@Prop' decorated attribute 'enablementItem' must be of the string, number, or boolean type. <etsLint>
HarmonyOS 鸿蒙Next ‘@Prop’ decorated attribute ‘enablementItem’ must be of the string, number, or boolean type. <etsLint> 因为,最新的DevEco Studio NEXT Developer Beta6只支持next系统,之前HarmonyOs系统的手机识别不了,所以我用的是devecostudio-windows-3.1.0.501。
问题是,再按照快速开始里的代码(网格和列表组件的使用-HarmonyOS应用开发快速入门-Codelabs-华为开发者联盟 (huawei.com))进行学习时,出现如题的错误。
但是,代码可以正常运行。
class ArticleClass {
id: string = '';
imageSrc: ResourceStr = '';
title: string = '';
brief: string = '';
webUrl: string = '';
constructor(id: string, imageSrc: ResourceStr, title: string, brief: string, webUrl: string) {
this.id = id;
this.imageSrc = imageSrc;
this.title = title;
this.brief = brief;
this.webUrl = webUrl;
}
}
@Component
export struct EnablementItem{
[@Prop](/user/Prop) enablementItem: ArticleClass;
build(){
Column(){
Image(this.enablementItem.imageSrc)
.width('100%')
.height(96)
.borderRadius({
topLeft: 16,
topRight: 16
})
.objectFit(ImageFit.Cover)
Text(this.enablementItem.title)
.height(19)
.width('100%')
.fontSize(14)
.textAlign(TextAlign.Start)
.textOverflow({ overflow: TextOverflow.Ellipsis })
.maxLines(1)
.fontWeight(400)
.padding({ left: 12, right: 12 })
.margin({ top: 8 })
Text(this.enablementItem.brief)
.height(32)
.width('100%')
.fontSize(12)
.textAlign(TextAlign.Start)
.textOverflow({ overflow: TextOverflow.Ellipsis })
.maxLines(2)
.fontWeight(400)
.fontColor('rgba(0, 0, 0, 0.6)')
.padding({ left: 12, right: 12 })
.margin({ top: 2 })
}
.width(160)
.height(169)
.borderRadius(16)
.backgroundColor(Color.White)
}
}
错误信息
The ‘@Prop’ decorated attribute ‘enablementItem’ must be of the string, number, or boolean type.
更多关于HarmonyOS 鸿蒙Next '@Prop' decorated attribute 'enablementItem' must be of the string, number, or boolean type. <etsLint>的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
我用5.0.1.600正常的,3.1.0.501版本较低不太好复现了。建议老师试试新版本
更多关于HarmonyOS 鸿蒙Next '@Prop' decorated attribute 'enablementItem' must be of the string, number, or boolean type. <etsLint>的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中,@Prop
装饰器用于声明组件的属性,并且这些属性必须是字符串、数字或布尔类型。根据帖子标题中的错误信息,enablementItem
属性不符合这些类型要求,因此触发了etsLint
的检查错误。确保enablementItem
的类型为string
、number
或boolean
即可解决此问题。
在HarmonyOS鸿蒙Next开发中,@Prop
装饰器用于声明一个父子组件之间传递的属性。根据错误提示,enablementItem
属性必须是string
、number
或boolean
类型之一。你需要检查enablementItem
的类型定义,确保它符合这些基本类型。例如:
@Prop enablementItem: string; // 或 number 或 boolean
确保在父组件中传递的值也是这些类型之一,以避免类型不匹配的错误。