当前位置:   article > 正文

使用pinia报错“getActivePinia was called with no active Pinia?“_为什么mian.ts写axios请求会导致pinia初始化报错问题

为什么mian.ts写axios请求会导致pinia初始化报错问题

使用步骤

1、首先创建store.ts文件

	import { createPinia } from "pinia";
	const pinia = createpinia();
	export default pinia;
  • 1
  • 2
  • 3

2.在mian.ts中引入

	import { createApp } from "vue"
	import App from './App.vue'
	import pinia from "./store/store"
	const app = createApp(App)
	app.use(pinia)
  • 1
  • 2
  • 3
  • 4
  • 5

3.在router.ts中使用pinia

	import { createRouter, createWebHistory } from 'vue-router'
	import pinia from '../store/store' 
	import { useUser} from "../store/useUser"
	const store = useUser(pinia)// 这里一定要把 pinia传入进去
	console.log(store) 
	
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

或者是axios.ts文件

	import axios from 'axios'

	import pinia from '../../stores/stores' 
	import { useCounterStore } from "../../stores/globalVariable"
	const global = useCounterStore(pinia)// 这里一定要把 pinia传入进去
	console.log(global) 
	
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/225645
推荐阅读
相关标签
  

闽ICP备14008679号