feat: 增加 pinia 基本结构

master
SuJiehao 2 years ago committed by dongmu
parent f47477285d
commit 2e3ff65e27

@ -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"
},

@ -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,
}

@ -0,0 +1,7 @@
import { createPinia } from 'pinia'
// 创建pinia实例
const pinia = createPinia()
// 导出pinia实例给main使用
export default pinia

@ -0,0 +1,25 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
// 定义 Store
export const useMemberStore = defineStore('member', () => {
// 会员信息
const profile = ref<any>()
// 保存会员信息,登录时使用
const setProfile = (val: any) => {
profile.value = val
}
// 清理会员信息,退出时使用
const clearProfile = () => {
profile.value = undefined
}
// 记得 return
return {
profile,
setProfile,
clearProfile,
}
})
Loading…
Cancel
Save