purchase-let/store/user.js

25 lines
655 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)
}
const token = ref(uni.getStorageSync('token')||'');
const setToken = (data) => {
token.value = data;
uni.setStorageSync('token', data)
}
return { userInfo, setToken, token, setToken }
})
export default useUserStore;