Vue project error: "TypeError: Cannot read properties of undefined (reading 'init')"

Table of contents

background

Solution


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';

 

Guess you like

Origin blog.csdn.net/weixin_56035334/article/details/126242254