一, 修改 productionSourceMap 为 false
在 config??index.JS??build
productionSourceMap: false,
默认为 true, 改为 false 有两大优点, 代码体积变小, 安全. 原因请百度.
二, 异步与懒加载
1, 路由
- import vue from 'vue'
- import Router from 'vue-router'
- Vue.use(Router)
- const HomeCont = ()=>import("@/components/HomeCont")
- export default new Router({
- routes: [
- {
- path: '/',
- name: 'HomeCont',
- component: HomeCont,
- },
- ]
- })
2, 组件
- <Seckill ref="seckill">
- </Seckill>
- components: { Seckill:() => import('@/components/common/home_module/seckill'),
- },
异步路由打包会多出很多 JS 文件, 项目大时注意页面效果, 使用 swiper 插件时有个坑.
如果组件中用了 ref, 那要开启定时器, 不然报没定义.
- setTimeout(()=>{
- this.$refs.seckill
- },100)
3, 图片使用懒加载
三, 代码的写法
1, 注意 v-if 与 v-show
2,v-for 绑定 key
3, 减少 watch 的数据
来源: http://www.bubuko.com/infodetail-3372563.html