Vue问题汇总

 

Vue——父子组件间异步动态获取数据传递数据时,子组件获取不到值或者延时获取:

通过watch解决:https://blog.csdn.net/where_slr/article/details/99552087

 

Vue中数据的异步加载:
1.通过watch、computed
2.在组件生命周期中的created阶段接收数据,后面操作可正常拿到数据
3.使用async、await,注意await后面要接promise对象才生效,示例:

    async get_region_statistic() {
      await region_statistic().then(response => {
        for (let item of response.data) {
          // let tmp_var = {}
          // tmp_var['name'] = item['region']
          // tmp_var['value'] = item['value']
          // console.log(response.data)
          item = JSON.parse(JSON.stringify(item).replace(/region/g, 'name'))
          item['name'] = this.regionMap[item['name']]
          this.region.push(item['name'])
          this.list.push(item)
        }
      })
      // 异步返回结果后再初始化图表
      this.$nextTick(() => {
        this.initChart()
      })
    },

 

posted @ 2019-11-27 19:49  whitesky-root  阅读(136)  评论(0编辑  收藏  举报