一、全局引入

在main.js中引入:

1 // 引入echarts
2 import echarts from 'echarts'
3 
4 Vue.prototype.$echarts = echarts

 

Hello.vue中的methods中:

// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(document.getElementById('myChart'))

 

二、按需引入

Hello.vue中:

1 // 引入基本模板
2 let echarts = require('echarts/lib/echarts')
3 // 引入柱状图组件
4 require('echarts/lib/chart/bar')
5 // 引入提示框和title组件
6 require('echarts/lib/component/tooltip')
7 require('echarts/lib/component/title')

 

在methods:中:

// 基于准备好的dom,初始化echarts实例
let myChart = echarts.init(document.getElementById('myChart'))

注意: 这里全局引入是 this.$echarts.init() 按需引入是:echarts.init()

 

相关文章:

  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2023-04-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
相关资源
相似解决方案