Table of contents
background
Introduce the echarts plug-in into the Vue project and find the following error:
[Vue warn]: Error in mounted hook: "TypeError: Cannot read properties of undefined (reading 'init')"
The way to introduce it in the component is: import on demand
// 引入echarts
import echarts from 'echarts';
export default {
name:"",
mounted() {
// 初始化echarts实例
let lineCharts = echarts.init(this.$refs.charts);//按需引入
}
Solution
change import method
import * as echarts from 'echarts';