npm install
npm run serve
npm run build
npm run lint
- 使用
unplugin-vue-components
及unplugin-auto-import
,可以不局部引用vant/vue/vue-router/vuex等模块 webpack
配置,全局引入scss
变量和混合axios
引入- 通用
request
配置 - 添加
config
控制变量的ts
兼容
- 通用
-
全局引入
css
,避免每个组件引入scss
变量sass-loader 版本10+
-
生产环境移除log
terser-webpack-plugin 版本4+
-
按需引入vant3
-
components.d.ts
使用按需加载unplugin-vue-components 时自动生成,添加到tsconfig
及git
忽略 -
setup
获取全局变量$toast
,使用时每次都需引入(与封装再引用无异,未使用)const instance = getCurrentInstance(); //@ts-ignore console.log(instance.proxy.$toast("123"));
-
组件
props
如果是对象最好给默认参数,只给required
会死循环报错 -
添加
router
默认路由配置 -
页面通用布局,兼容
ios
底部,兼容上拉加载,scroll
方法要使用在.page
上,且高度大于屏幕高度 -
页面切换动画(效果不理想,未使用)
-
keep-alive
,生命周期更换 -
全局初始化
Toast
配置,停留时间等 -
setup
使用name
最后方案define-options;官方提供两种方式setup name- 直接使用文件命名
- 两个script
-
vue3
在chrome
警告Added non-passive event listener to a scroll-blocking 'touchstart' event,暂未处理 -
ts
使用 ,遍历自己取值(Recordable
)
-
vuex替换成pinia,参考pinia分支
-
setup
语法糖使用,参数setup分支- unplugin-auto-import
API
自动导入,vue
/vue-router
/@/store
(unplugin-vue-components
已自动导入vant
) - eslint校验 兼容
defineExpose
等(升级cli5后已兼容) - 其他引入 顶级变量定义未使用报错(升级cli5后已兼容)
- unplugin-auto-import
-
升级vue-cli5,ts版本也升级(~4.5.5)
-
defineProps
在setup语法糖里是否正常显示(升级cli5后已兼容) -
webstorm
projectErrors
报错TS1232: An import declaration can only be used at the top level of a namespace or module.
setup语法糖中import引用(升级cli5后,依然报错,待升级webstorm,升级2022.2.1后依然报错提示) - Fn放到types文件夹里时,编辑器不报错,代码打包报错
-
prettier
检测到define-options
格式异常(升级cli5后已兼容) - debounced.ts中setTimeout报错(升级cli5后已兼容)
- webpack4 vs webpack5 迁移
-
overlay
移到client
内 -
disableHostCheck
改成allowedHosts
-
client
内progress
编译进度
-
- webpack5 优化
- 开启1500毫秒聚合编译,防止编辑器格式化代码导致重复构建
-
cache
开启二次启动缓存优化 -
SpeedMeasurePlugin
webpack打包分析
-
-
noResult组件改成ts
-
setup里的生命周期调用情况
vuex
vspinia
Compared to Vuex, Pinia provides a simpler API with less ceremony, offers Composition-API-style APIs, and most importantly, has solid type inference support when used with TypeScript.
vuex4.x
劣势
ts
支持不好,要写一堆接口,有些是vuex
自带的方法- 模块化后
state
不能合并,提示异常 - 使用不方便
injection
key
(可封装)
pinia
比较
mutations
移除- 更好的
ts
支持 - 使用方便,不用注入
key
- 扁平化模块
- 无需命名空间
替换问题
- 组合式API中使用pinia,注册pinia在初始化之后,导致组合式API中getters拿不到初始值报错
- 自动引入API
- vue tools使用
$reset
使用时只恢复没有muations
前的数据,如果初始化从localstorage
获取赋值了,是清空不了的
- Vue2.x 最令人诟病的一点就是对 Typescript 的羸弱支持,其根源也在于 vue2.x 的 api 大量使用了 this,造成其类型难以推断,Vue2.5 通过 ThisType 对 vue 的 typescript 支持进行了一波增强,但还是有不足之处,
- Vue3 的一个大的卖点也是改进了增强了对 Typescript 的支持。
typescript
支持度比较好,比如.vue``template
内的检测- 社区活跃,支持各种插件
- 轻便,不占内存
- markdown支持lint校验,统一样式
- 集成度比较高,开箱即用
git
模块yyds,支持分支对比等实用功能webstorm compile
编译js,可以手动控制需要编译查看的文件SFC
内template
的ts
兼容不好,比如:vant
组件内的v-model
及数据引用校验