Ustinian_ 2022-04-10 23:19 采纳率: 83.3%
浏览 251
已结题

Vue2.x使用echarts 在echarts实例化时报错

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图

index.html中引入echarts文件

<!-- 引入echarts文件后 window.echarts -->
        <script src="static/lib/echarts.min.js"></script>

在main.js中 将全局echarts挂载到Vue的原型对象上

// 将全局echarts挂载到Vue的原型对象上
// 别的组件中 this.$echarts
Vue.prototype.$echarts = window.echarts

在trendCom.vue中实例化echarts对象

this.chartInstance = this.$echarts.init(this.$refs.trend_ref)

运行结果及报错内容
[Vue warn]: Error in mounted hook: "TypeError: Cannot read properties of undefined (reading 'getAttribute')"

found in

---> <TrendCom>
       <TrendPage> at src/views/trendPage.vue
         <App> at src/App.vue
           <Root>
warn @ vue.runtime.esm.js?c320:619
logError @ vue.runtime.esm.js?c320:1893
globalHandleError @ vue.runtime.esm.js?c320:1888
handleError @ vue.runtime.esm.js?c320:1848
invokeWithErrorHandling @ vue.runtime.esm.js?c320:1871
callHook @ vue.runtime.esm.js?c320:4235
insert @ vue.runtime.esm.js?c320:3158
invokeInsertHook @ vue.runtime.esm.js?c320:6390
patch @ vue.runtime.esm.js?c320:6609
Vue._update @ vue.runtime.esm.js?c320:3963
updateComponent @ vue.runtime.esm.js?c320:4081
get @ vue.runtime.esm.js?c320:4495
run @ vue.runtime.esm.js?c320:4570
flushSchedulerQueue @ vue.runtime.esm.js?c320:4326
eval @ vue.runtime.esm.js?c320:1989
flushCallbacks @ vue.runtime.esm.js?c320:1915
Promise.then (async)
timerFunc @ vue.runtime.esm.js?c320:1942
nextTick @ vue.runtime.esm.js?c320:1999
queueWatcher @ vue.runtime.esm.js?c320:4418
update @ vue.runtime.esm.js?c320:4560
Vue.$forceUpdate @ vue.runtime.esm.js?c320:3984
eval @ index.js?0e5a:244
eval @ index.js?0e5a:242
eval @ index.js?0e5a:119
eval @ trendCom.vue?6f0b:28
./src/components/trendCom.vue @ app.js:41
__webpack_require__ @ app.js:374
_requireSelf @ app.js:648
apply @ app.js:1352
(anonymous) @ app.js:890
internalApply @ app.js:888
(anonymous) @ app.js:825
waitForBlockingPromises @ app.js:779
(anonymous) @ app.js:823
Promise.then (async)
(anonymous) @ app.js:822
Promise.then (async)
(anonymous) @ app.js:802
Promise.then (async)
hotCheck @ app.js:793
check @ dev-server.js?2743:14
eval @ dev-server.js?2743:55
emit @ events.js?b914:153
reloadApp @ reloadApp.js?7531:46
ok @ index.js?abc1:175
eval @ socket.js?d6e0:60
client.onmessage @ WebSocketClient.js?5586:50
vue.runtime.esm.js?c320:1897 TypeError: Cannot read properties of undefined (reading 'getAttribute')
    at echarts.min.js:22:210725
    at Yd (echarts.min.js:22:210761)
    at Object.t.init (echarts.min.js:22:748697)
    at VueComponent.initChart (trendCom.vue?15e1:29:1)
    at VueComponent.mounted (trendCom.vue?15e1:18:1)
    at invokeWithErrorHandling (vue.runtime.esm.js?c320:1863:1)
    at callHook (vue.runtime.esm.js?c320:4235:1)
    at Object.insert (vue.runtime.esm.js?c320:3158:1)
    at invokeInsertHook (vue.runtime.esm.js?c320:6390:1)
    at VueComponent.patch [as __patch__] (vue.runtime.esm.js?c320:6609:1)

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

1条回答 默认 最新

  • 前行的枫_denglinbo 2022-04-11 09:10
    关注

    注意看这个:"TypeError: Cannot read properties of undefined (reading 'getAttribute')" 。看看你getAttribute方法有没有用错

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月4日
  • 已采纳回答 4月26日
  • 创建了问题 4月10日

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)