位置: IT常识 - 正文

pinia报错:getActivePinia was called with no active Pinia. Did you forget to install pinia?(getparameter报错)

编辑:rootadmin
pinia报错:getActivePinia was called with no active Pinia. Did you forget to install pinia? 项目场景:

推荐整理分享pinia报错:getActivePinia was called with no active Pinia. Did you forget to install pinia?(getparameter报错),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:getconnection报错,getparameter报错,getch()报错,gets报错,getch出错,getaccinfo error,gets报错,getch出错,内容如对您有帮助,希望把文章链接给更多的朋友!

项目:vue3+pinia+vite+element-plus

问题描述

pinia.mjs:1692 Uncaught Error: [🍍]: getActivePinia was called with no active Pinia. Did you forget to install pinia?

pinia报错:getActivePinia was called with no active Pinia. Did you forget to install pinia?(getparameter报错)

错误:在没有激活Pinia的情况下调用getActivePinia。

报错代码:login.ts文件下

import { useUserStore } from '../../store/user'import { useRoute } from 'vue-router'const user = useUserStore()

报错位置:login.ts文件执行位置: layout组件中。

原因分析:

报错:在没有激活Pinia的情况下调用getActivePinia

分析:

login.ts中应用了pinia状态管理main.ts文件中尚未app.use(store),已经在layout文件中运行了login.ts文件

这里的问题像是异步导致的(不确定),main.ts中app.use(store).use(router).mount(“#app”),先挂store再挂router也不行,所以猜测是异步。

解决方案:import store from '@/store/index.ts'import { useUserStore } from '../../store/user'import { useRoute } from 'vue-router'const user = useUserStore(store)

以上是vue3中pinia的用法,在需要的页面再次引入pinia实例store即可。不同的是,其他页面引入,只需用const user = useUserStore(),激活pinia前引入需要传入pinia实例:const user = useUserStore(store)。

本文链接地址:https://www.jiuchutong.com/zhishi/269613.html 转载请保留说明!

上一篇:网购iphone注意什么 网购iphone6s怎么验货(网购iphone注意什么)

下一篇:不用iTunes如何将iPhone和iPad同步到Mac?新版macOS Catalina升级方法汇总(不用itunes怎么下载软件)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络