vue3+ts 项目遇到的问题和bug

1.router中使用pinia报错

js 复制代码
pinia.mjs:1709 Uncaught Error: [🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"?
See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help.
This will fail in production.
    at useStore (pinia.mjs:1709:19)
    at index.ts:6:15

分析原因:因为在mian.js中,注册router总比pinia先,所以不能使用到store/index.js文件中createPinia方法

解决方法:把store实例化放到路由守卫函数里面

js 复制代码
import { createRouter } from 'vue-router'
const router = createRouter({
  // ...
})

// ❌ 由于引入顺序的问题,这将失败
const store = useStore()

router.beforeEach((to, from, next) => {
  // 我们想要在这里使用 store
  if (store.isLoggedIn) next()
  else next('/login')
})

router.beforeEach((to) => {
  // ✅ 这样做是可行的,因为路由器是在其被安装之后开始导航的,
  // 而此时 Pinia 也已经被安装。
  const store = useStore()

  if (to.meta.requiresAuth && !store.isLoggedIn) return '/login'
})

参考:
添加链接描述
pinia

2.路由报错

js 复制代码
vue-router.mjs:35 [Vue Router warn]: No match found for location with path "/"
warn @ vue-router.mjs:35
显示另外 1 个框架
收起

参考:

https://blog.csdn.net/weixin_45952652/article/details/131192829

https://blog.csdn.net/m0_64344940/article/details/130710796

3.vue 样式穿透

js 复制代码
[@vue/compiler-sfc] ::v-deep usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead of ::v-deep <inner-selector>.

把::v-deep 替换为 :deep()

参考:

https://blog.csdn.net/weixin_43405300/article/details/132099608

相关推荐
C_心欲无痕几秒前
react - useState更新机制(直接更新和函数式更新)
前端·javascript·react.js
GDAL2 分钟前
Tailwind CSS 菜单实现全面讲解教程(基于书签篮网站场景)
前端·css·菜单
m5655bj7 分钟前
如何通过 C# 实现 PDF 页面裁剪
前端·pdf·c#
这是个栗子7 分钟前
前端开发中的常用工具函数(持续更新中...)
前端·javascript·算法
zhangsansecond9 分钟前
vs创建 基于ASP.NET Framework 的 SOAP 协议 Web 服务,https无法访问
前端·https·asp.net
爱上妖精的尾巴10 分钟前
6-13 WPS JS宏 Map实例2--拆分记录到表格
javascript·restful·wps
Reese_Cool13 分钟前
一篇文章梳理 HTML + CSS 核心知识(含响应式与 Sass)
前端·css·html
幽络源小助理14 分钟前
SpringBoot+Vue多维分类知识管理系统源码 | Java知识库项目免费下载 – 幽络源
java·vue.js·spring boot
雄鸡三声天下白16 分钟前
js复制文本到剪贴板,以及navigator.clipboard 会提示 is undefined
前端·javascript·数据库
OpenTiny社区17 分钟前
博文精读:Chrome CSS 2025年回顾
前端·css·chrome·开源·opentiny