在Vue3中的路由里面使用Pinia报错:

代码如下:

import { createRouter, createWebHistory } from 'vue-router'
import routes from './routes'
import { userStore } from "@/store/user";const userStoreData = userStore(); // 注意这行代码位置!!!!const router = createRouter({history: createWebHistory(),routes
})router.beforeEach((to, form, next) => {document.title = `${to.meta.title} | 管理系统`const role = userStoreData.msUserNameif (!role && to.path !== '/login') {next('/login')} else if (to.meta.permission) {// 简单模拟下如果是管理员权限,那么可以进入role === "admin" ? next() : next('/403')} else {next()}
})
export default router

解决办法:Using a store outside of a component | Pinia

getActivePinia was called with no active Pinia. Did you forget to install pinia?相关推荐

  1. [pinia]报错信息:getActivePinia was called with no active Pinia. Did you forget to install pinia

    在优化vue的过程中,看到目前为止官方推荐的数据管理工具是pinia,而我使用的是vuex pinia的迁移非常快捷方便 所以接下来简要说明一下迁移过程中遇到的问题 迁移问题 getActivePin ...

  2. [pinia]getActivePinia was called with no active Pinia. Did you forget to install pinia?

    getActivePinia was called with no active Pinia. Did you forget to install pinia? https://github.com/ ...

  3. 外部js文件中调用pinia时,报错getActivePinia was called with no active Pinia. Did you forget to install pinia?

    分析原因:是pinia在main.js中还未注册好,便在其他文件中使用了它. 正确引用: src/stores/index.js文件 import { createPinia } from 'pini ...

  4. vue3使用Pinia进行全局状态管理,Pinia安装和使用,Pinia 和 Vuex的对比

    介绍--为什么要使用 Pinia? Pinia 是 Vue 的存储库,它允许您跨组件/页面共享状态. 如果您熟悉 Composition API,您可能会认为您已经可以通过一个简单的 export c ...

  5. getActivePinia was called with no active Pinia.

    在vue3中使用pinia的时候,遇到这样的问题: getActivePinia was called with no active Pinia. 说是实例在路由文件中使用的时候,pinia实例没有被 ...

  6. pinia与vuex的区别以及pinia的使用

    ###pinia 与 vuex 的区别 pinia 的优点 : 完整的 TypeScript 支持:与在 Vuex 中添加 TypeScript 相比,添加 TypeScript 更容易 极其轻巧(体 ...

  7. 在router中使用pinia报错解决

    在router中使用pinia(getActivePinia was called with no active Pinia. Did you forget to install pinia)报错解决 ...

  8. 在ts文件中使用pinia报错解决

    在ts文件中使用pinia(getActivePinia was called with no active Pinia. Did you forget to install pinia)报错解决 一 ...

  9. 中國IT從業人員如此之多,為什麼沒有流行世界的核心技術呢?例如,操作系統,編程語言,數據庫等...

    工业革命与文艺复兴 18世紀中葉,英國人瓦特改良蒸汽機之後,一系列技術革命引起了從手工勞動向動力機器生產轉變的重大飛躍.隨後傳播到英格蘭到整個歐洲大陸,19世紀傳播到北美地區.工業革命的基礎,是物理和 ...

  10. Pinia轻量级状态管理

    1.1核心概念 vuex中有四个核心概念: State Getters Mutaions Actions 在Pinia中: State Getters Actions 同步异步都支持 1.2基本示例 ...

最新文章

  1. cnn 预测过程代码_FPN的Tensorflow代码详解——特征提取
  2. 编程之美-寻找发帖“水王”方法整理
  3. html video 设置进度条不可拖动_PHP大文件切割上传并带上进度条功能,不妨一试...
  4. Qt中 Qstring 与QbyteArray的互相转换
  5. LiveVideoStack 2022迎春招聘
  6. 如何根据ABAP类的一个方法名称,反查出这个类的名称
  7. laravel-admin 开发 bootstrap-treeview 扩展包
  8. 如何构建AI驱动型智能服务?
  9. 微软亚研院华刚对科研的见解
  10. 运用Unity实现AOP拦截器[结合异常记录实例]
  11. leetcode python3 简单题205. Isomorphic Strings
  12. 低智商屌丝蒟蒻的2012成都题解
  13. ffmpeg转码之TS转PS
  14. (转)某期货系统漏洞致巨损二审在即 千万损失谁来买单?
  15. 字体怎么安装到vivo_老人用手机遇到操作麻烦?vivo远程协助及时解决问题
  16. GBK 汉字编码转换
  17. iOS手势UIGestureRecognizer的使用及手势冲突的解决办法【转】
  18. Java整数的所有质因数,用JAVA将一个正整数分解成质因数,例如输入90,打印出90=2*3*3*5...
  19. signature=c7580760a679f082e2d4960e4c2c7772,Signatures of moiré-trapped valley excitons in MoSe
  20. 51单片机undefined identifier问题求助

热门文章

  1. Linux unison 效率,linux inotify+unison双向同步环境部署
  2. 盾神与砝码称重java_[蓝桥杯][算法提高VIP]盾神与砝码称重 (Java代码)
  3. C++入门基础(上)
  4. 河北农业大学能不能学计算机,河北农业大学(专业学位)计算机技术考研难吗
  5. phpmail通过qq发邮箱失败_PHP下利用PHPMailer配合QQ邮箱下的域名邮箱发送邮件
  6. TIOBE 6 月编程语言排行榜:编程语言的长尾效应
  7. android go官方下载,GoFIT下载
  8. 做工作必须将心比心——感谢译者陈浩对我们的批评
  9. win10小课堂:如何彻底关闭windows defender
  10. 【名言警句】马太效应