vue引入echarts报错Cannot read properties of undefined (reading 'init')


下载echarts成功后,按照官方文档引入echarts:

在组件内引用:

import echarts from 'echarts'

echarts.init(document.getElementById('idname'));

  发现会报错

 

 idname也检查过,是存在的对象

解决办法:1、用require

let echarts = require('echarts');
let myChart = echarts.init(document.getElementById('idname'));

 2、

import * as echarts from 'echarts'
let myChart = echarts.init(document.getElementById('idname'));

  亲测可用


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM