1. 程式人生 > >vue引入echart.js打包時特別大

vue引入echart.js打包時特別大

link : https://www.cnblogs.com/strinkbug/p/5786222.html

一、i在html中新增script標籤如下:

<script src="//cdn.bootcss.com/echarts/3.2.2/echarts.simple.min.js"></script>

二、在webpack中配置echarts 在webpack.base.conf.js檔案內新增external選項,在module.exports內部,和entry平級;

externals: {

"echarts": "echarts"

},

externals中的key是給import的時候用的,value表示的是如何在global中訪問到該物件,這裡是window.echarts

三、在需要使用echart的vue頁面引入echart

import echarts from 'echarts'

this.myChart = echarts.init(document.getElementById('line1'))

this.myChart.setOption(option)