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)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章