Vue项目报错: “TypeError: Cannot read properties of undefined (reading ‘init‘)“

目录

背景

解决方法


背景

在Vue项目中引入echarts插件,发现如下报错:

[Vue warn]: Error in mounted hook: "TypeError: Cannot read properties of undefined (reading 'init')"

 在组件中引入的方式是:按需引入

// 引入echarts
import echarts from 'echarts';
export default {
    name:"",
    mounted() {
        // 初始化echarts实例
        let lineCharts = echarts.init(this.$refs.charts);//按需引入
}

解决方法

改变引入方法

import * as echarts from 'echarts';

猜你喜欢

转载自blog.csdn.net/weixin_56035334/article/details/126242254