自定义组件获取组件高度可使用.onAreaChange()回调函数,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...@Component struct HelloComponent { @State message: string = 'Hello, World!'; build() { // HelloComponent自定义组件组合系统组件Row和Text Row() { Text(this.message) .onClick(() => { // 状态变量message的改变驱动UI刷新,UI从'Hello, World!'刷新为'Hello, ArkUI!' this.message = 'Hello, ArkUI!'; }) } } } class HelloComponentParam { message: string = "" } @Entry @Component struct ParentComponent { param: HelloComponentParam = { message: 'Hello, World!' } @State sizeValue: string = '' build() { Column() { Text('ArkUI message') HelloComponent(this.param) .onAreaChange((oldValue: Area, newValue: Area) => { console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`) this.sizeValue = JSON.stringify(newValue) }) Divider() Text('new area is: \n' + this.sizeValue).margin({ right: 30, left: 30 }) } } }本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。
自定义组件获取组件高度可使用.onAreaChange()回调函数,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...
本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。