将项目升级到 Vue3 时遇到的一些坑

与其说是坑,更多可能是转向的不适应。

  1. slot 废除,导致自己封装的 tabbar 无效,需要采用新的 v-slot 语法

  2. setup 中使用 async await 写异步请求,导致页面空白,length 无法获取。在 Vue2 中在 created 生命周期里写网络请求,在 Vue3 中 created 没有了,但如果要照搬 Vue2 的思路,setup 会出现问题。

https://stackoverflow.com/questions/64009348/why-i-got-blank-when-use-async-setup-in-vue3

  1. ts的类型问题

https://stackoverflow.com/questions/46915002/argument-of-type-string-null-is-not-assignable-to-parameter-of-type-string

// 原先我是这样写的
user: JSON.parse(localStorage.getItem('user')) || {},
// ts中要这样写,考虑到本地没有的情况
user: JSON.parse(localStorage.getItem('user') || '{}') || {},
  1. this导致的一系列不适应,在 Vue2 中 this 执行 Vue 实例,很多地方,特别是 Vuex Vue-router 里使用广泛。

暂时就这些,第4条影响最广,转向函数式,冲呀。

你可能感兴趣的:(将项目升级到 Vue3 时遇到的一些坑)