echart的几种引用方式

3,716 阅读1分钟

echart的几种引用方式

1.通过标签方式直接引入构建好的echarts文件

<script src="echarts.min.js"></script>

2.npm安装echarts

npm install echarts --save var echarts = require('echarts')

或者可以按需引入图表组件

var echarts = require('echarts/lib/echarts') //引入ECharts主模块 require('echarts/lib/chart/bar') // 引入柱状图

可以按需引入的模块列表:

github.com/apache/incu…

3.使用ES Module

import * as echarts from 'echarts' Vue.prototype.$echarts = echarts

使用Vue.use()注册

mian.js
import Vue from 'vue'
import echarts from './echarts.js'
Vue.use(echarts)

new Vue({
...
})

echart.js

import Echarts from 'echarts'
export default {
    install(Vue){
        Vue.prototype.$echarts = Echarts
    }
}