微信小程序用 pinia数据化存储信息

import { defineStore } from 'pinia'

import { ref } from 'vue'

import type {LoginResult} from '@/types/member'

//定义 Store

export const useMemberStore = defineStore(

'member',

() => {

// 会员信息

const profile = ref<LoginResult>()

//保存会员信息,登录时使用

const setProfile = (val: LoginResult) => {

profile.value = val

}

//清理会员信息,退出时使用,赋值undefined

const clearProfile = () => {

profile.value = undefined

}

//记得 return

return {

profile,

setProfile,

clearProfile,

}

},

//TODO:持久化

{

//persist: true,

//注意:微信小程序的本地存储,和H5本地存储不一样,必须写 storage: { setItem(){},

getItem(){} }

persist: {

//调整为兼容多端的API

storage: {

getItem(key) {

return uni.getStorageSync(key) // [!code warning]

},

setItem(key, value) {

uni.setStorageSync(key, value) // [!code warning]

},

},

},

},

)

相关推荐
星光一影2 小时前
陪诊陪检系统源码,陪诊小程序,陪诊APP,陪诊服务,家政上门系统,居家护理陪护源码
mysql·小程序·uni-app·php
阿奇__3 小时前
uniapp h5 app 小程序获取当前定位
小程序·uni-app
2501_915106326 小时前
iOS性能调优的系统化实践,从架构分层到多工具协同的全流程优化指南(开发者深度版)
android·ios·小程序·架构·uni-app·iphone·webview
李纲明8 小时前
Wordpress如何选择适合外贸的模板主题?
微信小程序·php
一 乐9 小时前
游戏助手|游戏攻略|基于SprinBoot+vue的游戏攻略系统小程序(源码+数据库+文档)
数据库·vue.js·spring boot·后端·游戏·小程序
说私域21 小时前
开源AI智能名片链动2+1模式S2B2C商城小程序:分享经济时代的技术赋能与模式创新
人工智能·小程序·开源
一人一程温一壶酒21 小时前
微信小程序uniapp开发附源码——图片加水印
微信小程序·uni-app·notepad++
低代码布道师1 天前
医疗小程序05我的就诊卡
低代码·小程序
阿拉斯加的头头儿1 天前
小程序下载图片问题处理
小程序
一 乐1 天前
校园墙|校园社区|基于Java+vue的校园墙小程序系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·后端·小程序