echarts警告 Can‘t get DOM width or height. Please check dom.clientWidth and dom.clientHeight. They sho

报错截图

在这里插入图片描述

问题

虽然在class中设置了width`height`,但是控制台还是发出了警告

上网一查,发现有很多网友也出现了类似的问题,在github中提了个issue
github isssue上有类似的问题:https://github.com/apache/echarts/issues/4569

解决办法

初始化的时候无法获取 domclientWidthclientHeight,新版本支持初始化的时候指定高宽,http://echarts.baidu.com/api.html#echarts.init

// 当echarts被封装成一个组件时,height和width作为props传入
const myChart = this.$echarts.init(
  ele,
  theme,
  {
    
    
    height: this.height,
    width: this.width,
  },
)

猜你喜欢

转载自blog.csdn.net/weixin_41886421/article/details/130433973