elementUI 引入echarts 图表 报错 Error: Initialize failed: invalid dom.

 

 如上图,报错 Error in nextTick: "Error: Initialize failed: invalid dom."

dom未挂载完成,图表已经开始初始化了。

解决办法:

根据id获取图表信息换成,refsthis.nextTick(() => ()})方法。

组件中代码如下:

复制代码
<template>
  <div class="box">
    <div :ref="info[0].chartId" class="chart"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'login',
  data () {
    return {
    }
  },
  props: [
    'info'
  ],
  methods: {
    initChart () {
      var myChart = echarts.init(this.$refs[this.info[0].chartId])
      myChart.setOption({
        title: {
          text: this.info[0].title
        },
        color: ['#91cc75', '#ee6666', '#73c0de', '#fac858', '#5470c6'],
        tooltip: {},
        xAxis: this.info[0].xAxis,
        yAxis: {},
        series: this.info[0].series
      })
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.initChart()
    })
  }
}
</script>
<style scoped lang="scss">
.chart{
  width: 100%;
  height: 100%;
}
</style>
复制代码

 

 
posted @   烂笔头~  Views(3006)  Comments(0Edit  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示