vue整合echarts时异步加载的数据无法渲染

2025-03-21

siteList数据由父组件发起异步请求后获得并传递给子组件,但是在mounted等生命周期中调用初始化echarts图表的方法initChart(),确无法正常渲染,此时使用watch深度监听siteList并在handler函数中调用initChart()便可正常渲染。

props:['siteList'], 
watch: {
    siteList: {
      deep: true,
      immediate: true,
      handler () {
        // 初始化图表
        this.initChart()
      }
    }
  },
  methods: {
    initChart() {
      const chart = echarts.init(document.getElementById('VulnerabilityRanking'))
      const options = this.getChartOptions()
      chart.setOption(options)
    },
  }

PREV
python使用poetry创建虚拟环境
NEXT
ubuntu开启root登录