This commit is contained in:
X1627315083
2025-10-21 10:22:12 +08:00
6 changed files with 909 additions and 78 deletions

View File

@@ -1,26 +1,42 @@
// 每一个存储的模块命名规则use开头store结尾
import { defineStore } from 'pinia'
export const useUserInfoStore = defineStore({
id: 'userInfo', // 必须指明唯一的pinia仓库的id
state: () => {
return {
num: 0,
name: '张三',
token: ''
}
},
getters: {
doubleCount: (state) => state.num * 2
},
actions: {
changeNum() {
this.num++
},
loginOut() {
// 处理退出登录的一些逻辑
return new Promise((rez) => {
rez('111')
})
}
import { ref, computed } from 'vue'
export const useUserInfoStore = defineStore('userInfo', () => {
// state
const num = ref(0)
const name = ref('张三')
const token = ref('')
// getters
const getUserInfo = computed(() => ({
num: num.value,
name: name.value,
token: token.value
}))
// actions
const setUserInfo = (data: any) => {
name.value = data.name
token.value = data.token
}
const loginOut = () => {
// 处理退出登录的一些逻辑
return new Promise((rez) => {
rez('111')
})
}
return {
// state
num,
name,
token,
// getters
getUserInfo,
// actions
setUserInfo,
loginOut
}
})