- 在父组件Father中使用@Local绑定数据reviewVote。
@Entry
@ComponentV2
struct Father {
@Local reviewVotes: number = 0;
build() {
Column() {
Son({ reviewVotes: this.reviewVotes })
Button(`Father: ${this.reviewVotes}`)
}
}
} - 子组件Son中使用@Param接收父组件Father传递的参数reviewVote。
@ComponentV2
struct Son {
@Require @Param reviewVotes: number = 1;
build() {
Column() {
Grandson({ reviewVotes: this.reviewVotes })
}
}
} - 孙子组件Grandson 使用@Param接收Son组件传递的参数reviewVote。
@ComponentV2
struct Grandson {
@Require @Param reviewVotes: number = 1;
build() {
Column() {
Button(`Grandson: ${this.reviewVotes}`)
}.width('100%')
}
}