posts - 609,  comments - 13,  views - 64万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
1、之前在main.js中使用方式是:
import { createPinia } from 'pinia'
const pinia = createPinia();
app.use(pinia);
2、现在的问题是我要再建一个js文件,需要用到我建的pinia的store,然后报错:getActivePinia was called with no active Pinia. Did you forget to install pinia?
问题就是要重新在这个js文件中注册一下pinia
解决办法,为pinia单独新建一个文件store.js 内容也很简单,就三行
import { createPinia } from 'pinia';
const pinia = createPinia();
export default pinia;
3、然后在要使用pinia的js文件中导入,也很简单
import pinia from '@/stores/store'
import { useSystemDataStore } from "@/stores/index";
// SystemDataStore 可以在本文件中随意使用
const SystemDataStore = useSystemDataStore(pinia);
然后就可以使用 SystemDataStore.apiDomain 或者 useSystemDataStore().apiDomain 都可以,因为已经注册过了pinia
posted on   邢帅杰  阅读(14368)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
点击右上角即可分享
微信分享提示