1.新建store文件
新建index.js,代码:
// import {
// createPinia
// } from 'pinia'
//const store = createPinia()
import * as Pinia from 'pinia'
const pinia = Pinia.createPinia()
export * from "./modules/user"
export * from "./modules/me"
export * from "./modules/order"
export * from "./modules/socket"
export default pinia
2.在mian.js 加上代码
这个能在vue和nvue文件上执行
import {
createSSRApp
} from 'vue'
import * as Pinia from "pinia";
import pinias from "@/store";
export function createApp() {
const app = createSSRApp(App)
const store = Pinia.createPinia();
app.use(pinias);
app.use(store);
return {
app,
Pinia
}
}
这个只能在vue文件执行
import {
createSSRApp
} from 'vue'
import pinia from "@/store";
export function createApp() {
const app = createSSRApp(App)
app.use(pinia);
return {
app,
Pinia
}
}
页面调用
import {
useUserStore
} from "@/store/index.js"
const userStore = useUserStore()