OpenHarmony开发者论坛

标题: 数据赋值以后UI不更新 [打印本页]

作者: wangyingfeng1    时间: 4 天前
标题: 数据赋值以后UI不更新
[md]写了一个头部展示信息的页面 通过网络请求获取数据一个 给对象赋值 但是UI确没有更新上去,经过实验发现是请求异步的问题导致的(因为如果把赋值一个假数据放到请求前面 UI就可以更新) 有没有好的结局方案呢

定了一个对象

```
export interface OutCallMarketingData {
  count?: string
  undialedCount?: string
  dialing?: string
  handledCount?: string
}
```

这个是初始化

```
  @State monthData: OutCallMarketingData = {}

```

这个是赋值请求方法

```

  async getMonthData() {
    let parm = authStore.getSSTParm();
    parm["customerType"] = '2'
    hdHttpsst.post<OutCallMarketingData>(OUTCALL_VISITRECORD_GETMONTH,
      parm).then(async (res: HdSSTResponse<OutCallMarketingData>) => {
      if (res.returnCode === "1000") {
        this.monthData = res.dataInfo
      } else {
      }
    })
  }
```

这个是相关UI

```
Row() {
          this.TopNumBuilder('未拨通', this.monthData.undialedCount ? this.monthData.undialedCount : '0')
          this.TopNumBuilder('已拨通', this.monthData.dialing ? this.monthData.dialing : '0')
          this.TopNumBuilder('已办理', this.monthData.handledCount ? this.monthData.handledCount : '0')
        }
```

```
@Builder
  TopNumBuilder(text: string, number: string) {
    Column({ space: 10 }) {
      Text(text).fontSize(13).fontColor(Color.White);
      Text(number).fontSize(22).fontWeight(FontWeight.Medium).fontColor(Color.White);
    }
    .justifyContent(FlexAlign.Center)
  }
```
[/md]
作者: 鸿蒙小语哥    时间: 4 天前
建议了解一下@Observed装饰器和@ObjectLink装饰器
https://developer.huawei.com/con ... d-and-objectlink-V5




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5