日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

TypeError:cannot read property ‘getAttribute‘ of undefined

作者:前端開心果 更新時間: 2023-07-31 編程語言

報錯場景:頁面切換路由時報錯
報錯原因:使用 Vue + echarts,因為 頁面中使用了 echarts 圖表,在初始化圖表后,dom 元素還未被初始化加載出來,導致 echarts 在渲染時候報錯
示例代碼:

drawPie(){ // 總體告警數 餅圖
  // 基于準備好的dom,初始化echarts實例
  let ref = this.$refs.pie
  if (ref && ref !== undefined) {
    let myChart = this.$echarts.init(ref)
    // 繪制圖表
    myChart.setOption({
      color: ['#04befe'],
      tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b}: {c}'
      },
      series: [
        {
          type: 'pie',
          radius: ['50%', '65%'],
          avoidLabelOverlap: true,
          label: {
            show: true,
            formatter: ' {c}\n\n{b}',
            fontSize: '16',
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: '16',
            }
          },
          labelLine: {
            show: false
          },
          data: [
            {value: this.total_num, name: '總體告警數'},
          ],
          hoverOffset: 2
        }
      ]
    })
  }
},

函數中直接調用 echarts 方法即可

原文鏈接:https://blog.csdn.net/qq_38157825/article/details/109319812

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新