1、html 中引入 文件
html中添加script標籤如下:
<script src="//cdn.bootcss.com/echarts/4.2.1/echarts.simple.min.js"></script>
css文件直接用link標籤引入
2、在 webpack 中配置使用 CDN
在vue.config.js中配置如下:
module.exports = {
configureWebpack: {
externals: {
'echarts': 'echarts' // 配置使用CDN
}
}
}
externals中的key是用於import,value表示的在全局中訪問到該對象,就是window.echarts
3、在vue文件中使用
在vue中使用echarts的時候無需 import echarts,可直接使用
configureWebpack 和 chainWebpack的區別:https://cli.vuejs.org/zh/guide/webpack.html#簡單的配置方式