HarmonyOS 鸿蒙Next Component 相关问题
HarmonyOS 鸿蒙Next Component 相关问题 PageA @Component
PageB @ComponentV2
PageA 中定义了:@Provide showTipsDialog: boolean = false
请问PageB 中如何使用
2 回复
可以尝试如下方式传递变量,demo如下:
@Entry
@Component
struct ComponentV2Example {
private numbers: string[] = ["0", "2", "3"]
@Provide isShowDialog: boolean = false;
build() {
Column() {
Text("PageA:" + this.numbers.length)
Button('Change Status').onClick(() => {
this.isShowDialog = !this.isShowDialog;
}).margin({bottom: 24})
PageB({nums: this.numbers, isShow: this.isShowDialog})
}
}
}
@ComponentV2
struct PageB {
@Param nums: string[] = []
@Param isShow: boolean = false
build() {
Column() {
Text('PageB:' + this.isShow )
List() {
ForEach(this.nums, (item: string) => {
ListItem() {
Text(item)
}
})
}
}
}
}
更多@Compoent与@Component混合使用的变量传递限制条件:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-new-componentv2-V5#%E9%99%90%E5%88%B6%E6%9D%A1%E4%BB%B6
更多关于HarmonyOS 鸿蒙Next Component 相关问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html