2024-04-25 18:02:30 +08:00
|
|
|
// 导入定义仓库的方法
|
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
// 导入响应式和计算
|
|
|
|
import { ref } from 'vue';
|
|
|
|
|
|
|
|
const useUserStore = defineStore("user", () => {
|
|
|
|
|
|
|
|
// 定义一个状态用户信息
|
|
|
|
const userInfo = ref(uni.getStorageSync('userInfo')||{});
|
|
|
|
// 定义一个设置状态的方法
|
|
|
|
const setUserInfo = (data) => {
|
|
|
|
userInfo.value = data;
|
|
|
|
uni.setStorageSync('userInfo', data)
|
|
|
|
}
|
|
|
|
|
2024-04-28 18:08:57 +08:00
|
|
|
userInfo.value = {
|
|
|
|
"nickname": "哈哈",
|
2024-04-30 18:08:36 +08:00
|
|
|
"id": 1,
|
2024-04-28 18:08:57 +08:00
|
|
|
"mobile": "17685151643",
|
2024-04-30 18:08:36 +08:00
|
|
|
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/tFJnfhVKlAlIecticsOhjAu8CHa6ibZacWrcHHkiahu7f0dQlWYgwu1b0TPLSLlO1xCTa6KN1krqg3XSIo3vq6uCQ/132",
|
2024-04-28 18:08:57 +08:00
|
|
|
"token": "a8670fe7f1014c0f5125f6ca0c3b9cb3"
|
|
|
|
}
|
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
const token = ref(uni.getStorageSync('token')||'');
|
|
|
|
const setToken = (data) => {
|
|
|
|
token.value = data;
|
|
|
|
uni.setStorageSync('token', data)
|
|
|
|
}
|
2024-04-28 18:08:57 +08:00
|
|
|
token.value = "a8670fe7f1014c0f5125f6ca0c3b9cb3"
|
2024-04-25 18:02:30 +08:00
|
|
|
|
2024-04-30 18:08:36 +08:00
|
|
|
return { userInfo, setUserInfo, token, setToken }
|
2024-04-25 18:02:30 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
export default useUserStore;
|