logo小熊博客
首页 fk标记语言示例 登录
目录
鸿蒙开发,组件不刷新

在主页面定义一个变量

@State refreshHomeKey: number = 0;

在切换TabContent时候更改refreshHomeKey 值


Column() {
  Tabs({ barPosition: BarPosition.End, index: this.currentIndex }) {

    TabContent() {
      VehicleAssistant({ refreshKey: this.refreshHomeKey })
    }.tabBar(this.TabBuilder(0, '首页'))


  }
  .width('100%')
  .height('100%')
  .barMode(BarMode.Fixed)
  .onChange((index: number) => {
    console.log("Tab changed to: " + index)
    this.currentIndex = index

    // Tab切换时的刷新逻辑
    if (index === 0) {
      console.log("111111")
      this.refreshHomeKey ++
    }
  })
}

在tab页面监听refreshHomeKey 值的变化

@Prop @Watch('onRefreshKeyChanged') refreshKey: number = 0;

  // 监听 refreshKey 变化
  onRefreshKeyChanged() {
    this.loadCarInfo();
  }
下一篇:鸿蒙开发应用沉浸式效果
请我喝奶茶!
赞赏码
手机扫码访问
手机访问