✔ 掌握 echarts 的基本使用。
✔ 了解项目打包上线的基本流程。
首页-echarts图表的应用


- 安装 echarts 包。
1 | npm i echarts |
- 放置两个图表的 div,并给定高宽,
src/views/dashboard/index.vue
。
1 | <div class="chart"> |
- 在 mounted 中初始化图表,
src/views/dashboard/index.vue
。
1 | import CountTo from 'vue-count-to' |
首页-echarts图表的按需导入


echarts 图表的按需导入, src/views/dashboard/index.vue
。
1 | // 引入核心包,注意这儿是从 'echarts/core' 引入的 |
路由模式-将路由改成history模式

hash模式带#,#后面的地址变化不会引起页面的刷新
history没有#,地址变化会引起页面刷新,更符合页面地址的规范(开发环境不刷新-webpack配置)
将路由模式修改成history模式,
src/router/index.js
1 | const createRouter = () => new Router({ |
打包分析-分析

打包分析代码。
1 | npm run preview -- --report |

CDN加速

将几个比较大的多在打包时排除,这样可以缩小整体打包的大小,保证 js 的加载速度,排除的包采用 cdn 的方式用外链去引入,cdn 本名为分发服务器,意为更近的访问区间更快的访问速度将所需要的文件返回给客户端。
- webpack 排除打包,
vue.config.js
。
1 | configureWebpack: { |
- 在 html 中采用外链引入排除的文件,
public/index.html
。
1 |
|
项目打包-安装nginx

- 执行打包命令,得到 dist 文件包。
1 | npm run build:prod |
- 安装 nginx,双击
nginx.exe
启动服务。
- windows 下停止服务。
1 | ./nginx -s stop |
把 dist 中的代码放到 html 目录下。
清空 Cookie,浏览器地址栏输入
http://localhost/login
。
nginx解决history的404问题

修改 windows 配置文件,conf/nginx.conf
。
1 | location / { |
重启服务。
1 | ./nginx -s reload |
nginx配置代理解决生产环境跨域问题


nginx解决生产环境跨域

修改配置文件
1 | location /prod-api { |
windows重启服务
1 | ./nginx -s reload |