赞
踩
1、首先创建store.ts文件
import { createPinia } from "pinia";
const pinia = createpinia();
export default pinia;
2.在mian.ts中引入
import { createApp } from "vue"
import App from './App.vue'
import pinia from "./store/store"
const app = createApp(App)
app.use(pinia)
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)
或者是axios.ts文件
import axios from 'axios'
import pinia from '../../stores/stores'
import { useCounterStore } from "../../stores/globalVariable"
const global = useCounterStore(pinia)// 这里一定要把 pinia传入进去
console.log(global)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。