import { defineStore } from 'pinia' import { ref } from 'vue' // 定义 Store export const useDeviceStore = defineStore( 'device', () => { // 会员信息 const deviceInfo = ref() // 保存会员信息,登录时使用 const setDeviceInfo = (val) => { deviceInfo.value = val } // 清理会员信息,退出时使用 const clearDeviceInfo = () => { deviceInfo.value = undefined } // 记得 return return { deviceInfo, setDeviceInfo, clearDeviceInfo, } }, // TODO: 持久化 { // 网页端持久化 // persist: true, // 小程序端持久化 persist: { storage: { getItem(key) { return uni.getStorageSync(key) }, setItem(key, value) { uni.setStorageSync(key, value) }, }, }, }, )