Promise使用

这段代码展示了如何使用Promise处理异步操作,首先更新时间对象,然后调用queryDataReq方法查询数据。当数据返回并成功时,执行exportBefore方法。queryDataReq方法中,根据查询结果调用restore方法,并更新视图。
new Promise((resolve, reject) => {
   this.$refs.echarts.$refs[childRef].time=Object.assign(
     this.$refs.echarts.$refs[childRef].time, {'statDate': this.statDate,'type':this.type})
   this.$refs.echarts.$refs[childRef].queryDataReq(resolve)
}).then((data) => {
   this.$refs.echarts.$refs[childRef].exportBefore()
})
queryDataReq (callback) {
    queryAllStat(this.queryUrl, this.time).then(res => {
        if (res.data.code == 0) {
          callback && callback()
          this.restore(res.data.data)
        } else {
          this.restore()
        }
        this.setLastUpdateTime()
        this.updateView()
      }).catch(() => {
        this.restore()
        this.updateView()
      })
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值