当前位置:编程学习 > vue >>

echars组件 mounted 获取不到 created 里面api的值

vue使用echarts时created里拿到的数据无法渲染问题
简单做法,直接在mounted获取api数据
//正确代码
  async mounted() {
    //获取数据
    const res = await this.$http.get('yizuotu/net/1')
    this.option.legend.data = res.data.data.series.map((item) => item.name)
    this.option.series = res.data.data.series
//渲染
    let myChart = this.$echarts.init(this.$refs.myEchart)
    this.option && myChart.setOption(this.option)

  },


当然还可以延时获取,watch监视数据变化,以及组件传值,可以参看

Vue created/mounted 异步获取不到data中的数据

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,