微信小程序用 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 小时前
微信小程序学习实录14:微信小程序手写签名功能完整开发方案
学习·微信小程序·notepad++
说私域3 小时前
全民电商时代下的链动2+1模式与S2B2C商城小程序:社交裂变与供应链协同的营销革命
开发语言·人工智能·小程序·php·流量运营
2501_915106324 小时前
iOS 抓包工具实战实践指南,围绕代理抓包、数据流抓包和拦截器等常见工具
android·ios·小程序·https·uni-app·iphone·webview
莫桐4 小时前
微信小程序tab模块滚动至顶部导航栏置顶效果实现
微信小程序·小程序
sheji34164 小时前
【开题答辩全过程】以 基于微信小程序健康跑平台的设计与实现为例,包含答辩的问题和答案
微信小程序·小程序
棒棒的唐4 小时前
适合小程序使用的将对象数组转换为参数字符串方法
前端·javascript·小程序
努力学前端Hang4 小时前
微信小程序安装tdsign组件库
微信小程序·小程序
2501_915106325 小时前
如何在 iOS 设备上理解和分析 CPU 使用率(windows环境)
android·ios·小程序·https·uni-app·iphone·webview
weixin_177297220695 小时前
[特殊字符]旧物重生,绿色未来——旧物回收二手交易小程序,开启环保新生活[特殊字符]
小程序·生活
说私域5 小时前
链动2+1模式S2B2C商城小程序在电商直播中的应用与影响研究
大数据·人工智能·小程序·流量运营