Pinia报错需要重新创建

问题

vue3项目,在main.js中已经引入pinia,并且成功创建

在单独的js文件中想使用pinia,引入store import { useInfo} from '@store/info'

但是报错提示getActivePinia was called with no active Pinia. Did you forget to install pinia?

 

解决

1.需要额外创建一个store.js文件,用来给useInfo使用

import { createPinia } from 'pinia'
const pinia = createPinia()
export default pinia

2.在使用pinia的文件中引入这个store.js文件,并交给需要使用的store

import pinia from '@store/store'
import { useInfo } from '@store/useInfo'

const store = useInfo(pinia)

 

posted @   Karle  阅读(93)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
点击右上角即可分享
微信分享提示