微信小程序用 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]

},

},

},

},

)

相关推荐
小旭@1 小时前
uniapp 微信小程序遇到的坑
微信小程序·uni-app
某公司摸鱼前端1 小时前
uniapp 支付宝小程序自定义 navbar 无效解决方案
小程序·uni-app
旧人231 小时前
微信小程序 首页之轮播图和搜索框 代码分享
微信小程序·小程序
hi星尘7 小时前
深度解析:基于Python的微信小程序自动化操作实现
python·微信小程序·自动化
人工智能的苟富贵11 小时前
微信小程序直传阿里云 OSS 实践指南(V4 签名 · 秒传支持 · 高性能封装)
阿里云·微信小程序·小程序
时之彼岸Φ12 小时前
Fiddler+Yakit实现手机流量抓包和小程序抓包
智能手机·小程序·fiddler
换日线°12 小时前
微信小程序根据图片生成背景颜色有效果图
微信小程序
suncentwl13 小时前
为什么选择有版权的答题pk小程序
小程序·答题小程序·答题pk
小旋风0123414 小时前
uniapp自定义头部(兼容微信小程序(胶囊和状态栏),兼容h5)
微信小程序·uni-app·notepad++
GalenZhang88816 小时前
Java生成微信小程序码及小程序短链接
java·微信小程序·小程序