PanJiaChen / vue-admin-template

a vue2.0 minimal admin template
https://git.io/fAnuM
MIT License
20.03k stars 7.42k forks source link

[Echarts] TypeError: Cannot read property 'init' of undefined #607

Open SimZhou opened 4 years ago

SimZhou commented 4 years ago

Hi, so when using echarts, I followed the template from vue-element-admin, however i got TypeError: Cannot read property 'init' of undefined: error

So I checked the internet and found a solution. By adding the following two lines into my chart.vue fixs my problem:

import Vue from 'vue'
Vue.prototype.$echarts = echarts

(reference)

I am wondering why is this needed and why in vue-element-admin it does not need those two lines?

Similar issue on echarts: #187 (But mine is different, I just wanna know why I cannot do the same thing as vue-element-admin and get it right)

Robinlj commented 4 years ago

you need add three lines into the .vue file: import Vue from 'vue' import echarts from 'echarts' //this line you miss Vue.prototype.$echarts = echarts

HouseWei commented 3 years ago

If you use Echarts 5, you may add the following into your chart.vue var echarts = require('echarts');

raychengchang commented 3 years ago

If you use Echarts 5, you may add the following into your chart.vue var echarts = require('echarts');

Thanks HouseWei, you saved my day

hom commented 3 years ago

We can do like this also, it does well

import * as echarts from 'echarts'
junanzheng commented 3 years ago

We can do like this also, it does well

import * as echarts from 'echarts'

It works for me. Thanks

Denver-Ning commented 3 months ago

We can do like this also, it does well我们也可以这样做,效果很好

import * as echarts from 'echarts'

It works for me too.

Robinlj commented 3 months ago

你好,来件已收,我会尽快给你回复的,谢谢!