"getActivePinia()" was called but there was no active Pinia. Did you forget to install pinia?
时间: 2023-12-13 18:24:39 浏览: 136
14.(vue3.x+vite)组件间通信方式之pinia.rar
该错误提示意味着在调用"getActivePinia()"方法时,没有激活Pinia或者没有安装Pinia插件。这可能是因为您在主文件(main.js)中还没有正确注册Pinia插件。请按照以下步骤进行正确的引用和注册:
1. 在src/stores/index.js文件中,引入并创建Pinia实例,代码如下:
```javascript
import { createPinia } from 'pinia';
const pinia = createPinia();
export default pinia;
```
2. 在main.js文件中,正确注册Pinia插件,代码如下:
```javascript
import { createApp } from 'vue';
import App from './App.vue';
import pinia from './stores';
import router from './router';
import './configs/permission';
createApp(App).use(pinia).use(router).mount('#app');
```
确保您按照以上步骤正确引用和注册Pinia插件,这样就能解决"getActivePinia()" was called but there was no active Pinia. Did you forget to install pinia?的问题。
阅读全文