1. 程式人生 > >vue中引入echarts

vue中引入echarts

一. 簡述

vue專案中使用圖示庫echarts.

二. 步驟

  • 引用echarts:npm install echarts -s
  • 配置echarts:
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import elementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import echarts from 'echarts'

Vue.use(echarts)
Vue.use(elementUI)
Vue.config.productionTip = false
Vue.prototype.$echarts = echarts

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
  • 使用echarts:
  •  mounted() {
            this.bar = this.$echarts.init(document.getElementById(this.barId))
            this.bar.setOption(this.option)
        },