diff --git a/package.json b/package.json index 3ae9967..6c08cb6 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "@dcloudio/uni-mp-toutiao": "3.0.0-alpha-3061120221205002", "@dcloudio/uni-mp-weixin": "3.0.0-alpha-3061120221205002", "@dcloudio/uni-quickapp-webview": "3.0.0-alpha-3061120221205002", + "pinia": "^2.0.27", "vue": "^3.2.45", "vue-i18n": "^9.1.9" }, diff --git a/src/main.ts b/src/main.ts index 4b5dc40..1651699 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,11 @@ import { createSSRApp } from 'vue' +import pinia from './stores' import App from './App.vue' export function createApp() { const app = createSSRApp(App) + app.use(pinia) return { app, } diff --git a/src/stores/.gitkeep b/src/stores/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/stores/index.ts b/src/stores/index.ts new file mode 100644 index 0000000..68fa234 --- /dev/null +++ b/src/stores/index.ts @@ -0,0 +1,7 @@ +import { createPinia } from 'pinia' + +// 创建pinia实例 +const pinia = createPinia() + +// 导出pinia实例,给main使用 +export default pinia diff --git a/src/stores/modules/member.ts b/src/stores/modules/member.ts new file mode 100644 index 0000000..a0a29de --- /dev/null +++ b/src/stores/modules/member.ts @@ -0,0 +1,25 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' + +// 定义 Store +export const useMemberStore = defineStore('member', () => { + // 会员信息 + const profile = ref() + + // 保存会员信息,登录时使用 + const setProfile = (val: any) => { + profile.value = val + } + + // 清理会员信息,退出时使用 + const clearProfile = () => { + profile.value = undefined + } + + // 记得 return + return { + profile, + setProfile, + clearProfile, + } +})