purchase-let/store/user.js

33 lines
939 B
JavaScript
Raw Normal View History

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": "哈哈",
"mobile": "17685151643",
"avatar": "https://lihaiim.oss-cn-chengdu.aliyuncs.com/image/admin/avatar.png",
"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
return { userInfo, setToken, token, setToken }
})
export default useUserStore;