import promptAction from '@ohos.promptAction'
@Entry
@Component
struct WatchCase {
@State message: string = 'Hello World'
@State
@Watch('update')
num: number = 0
update() {
promptAction.showToast({message: this.num.toString()})
}
build() {
Row() {
Column() {
Text(this.num.toString()).fontSize(30)
Divider().strokeWidth(6).color(Color.Red)
ChildInfo({num: $num})
}
.width('100%')
}
.height('100%')
}
}
@Component
struct ChildInfo {
@Link
num: number;
build() {
Text(this.num.toString()).fontSize(30)
.onClick(() => {
this.num++
})
}
}
image.png
网友评论