使用Echarts报错:this.dom.getContext is not a function;

echarts 报错 this.dom.getContext is not a function;

原因:因为在初始化echarts的时候,echarts.js规定只能使用dom原生方法获取标签,document.getElementById('id');这里我结合vue使用 所以用的是$refs ,我印象中使用$refs是可以的,但是当我打印两个对象查看时 差异性就可以显现出来,一个是原生的dom对象,另一个却是Vue组件实例对象

 

代码部分:

    <div class="dashboard-chart">
      <div class="temperature">
        <el-card class="box-card" id="temperature" ref="temperature">
          
        </el-card>
      </div>
    </div>

mounted(){
    let myChart = echarts.init(document.getElementById('temperature'));
    // let myChart = echarts.init(this.$refs.temperature);
    console.log(document.getElementById('temperature'));
    console.log(this.$refs.temperature);
    console.log('byID'+document.getElementById('temperature'));
    console.log('$refs'+this.$refs.temperature);
    myChart.setOption(this.option,true)
    
  }

结果:这里是直接使用的一个官方案例

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值