purchase-let/store/user.js

36 lines
1.0 KiB
JavaScript

// 导入定义仓库的方法
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)
}
const token = ref(uni.getStorageSync('token')||'');
const setToken = (data) => {
token.value = data;
uni.setStorageSync('token', data)
}
// #ifdef H5
token.value = "a8670fe7f1014c0f5125f6ca0c3b9cb3"
userInfo.value = {
"nickname": "哈哈",
"id": 1,
"mobile": "17685151643",
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/tFJnfhVKlAlIecticsOhjAu8CHa6ibZacWrcHHkiahu7f0dQlWYgwu1b0TPLSLlO1xCTa6KN1krqg3XSIo3vq6uCQ/132",
"token": "a8670fe7f1014c0f5125f6ca0c3b9cb3"
}
// #endif
return { userInfo, setUserInfo, token, setToken }
})
export default useUserStore;