vue3+pinia,在beforeEach中调用接口导致报错,"getActivePinia()" was called but there was no active Pinia?

调用接口,报以下错误
vue3+pinia,在beforeEach中调用接口导致报错,"getActivePinia()" was called but there was no active Pinia?
在beforeEach中的代码
vue3+pinia,在beforeEach中调用接口导致报错,"getActivePinia()" was called but there was no active Pinia?
当调用接口的时候beforeEach中的console.log()都打印不出来
vue3+pinia,在beforeEach中调用接口导致报错,"getActivePinia()" was called but there was no active Pinia?
无打印结果
vue3+pinia,在beforeEach中调用接口导致报错,"getActivePinia()" was called but there was no active Pinia?
有大佬知道这是什么原因吗?
useUserStore中的代码
vue3+pinia,在beforeEach中调用接口导致报错,"getActivePinia()" was called but there was no active Pinia?
注册到app.vue中的代码
vue3+pinia,在beforeEach中调用接口导致报错,"getActivePinia()" was called but there was no active Pinia?


回答:

  1. 问题核心:确保你在使用 useXXXStore 之前,已经通过 createPinia 在根应用完成了注册。
  2. 你的问题可能是:

    1. 使用了路由守卫
    2. 启动路由的时候调用了 store 里的方法
    3. 但是此时 pinia 还没完成注册
  3. 其实跟你调用红框里的接口没什么干系

以上是 vue3+pinia,在beforeEach中调用接口导致报错,"getActivePinia()" was called but there was no active Pinia? 的全部内容, 来源链接: utcz.com/p/934495.html

回到顶部