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

},

},

},

},

)

相关推荐
00后程序员张1 小时前
python 抓包在实际项目中的合理位置,结合代理抓包、设备侧抓包与数据流分析
android·ios·小程序·https·uni-app·iphone·webview
2501_915918418 小时前
使用 HBuilder 上架 iOS 应用时常见的问题与应对方式
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074710 小时前
iOS 崩溃日志的分析方法,将崩溃日志与运行过程结合分析
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074711 小时前
React Native 混淆在真项目中的方式,当 JS 和原生同时暴露
javascript·react native·react.js·ios·小程序·uni-app·iphone
00后程序员张11 小时前
苹果应用商店上架App流程,签名证书、IPA 校验、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074711 小时前
iOS 上架需要哪些准备,围绕证书、描述文件和上传方式等关键环节展开分析
android·ios·小程序·https·uni-app·iphone·webview
qq_124987075311 小时前
基于微信小程序的私房菜定制上门服务系统(源码+论文+部署+安装)
java·spring boot·微信小程序·小程序·毕业设计·毕设
2501_9151063211 小时前
iOS 上架费用解析,哪些成本可以通过流程优化降低。
android·ios·小程序·https·uni-app·iphone·webview
换日线°12 小时前
微信小程序找不同游戏(有效果图)
游戏·微信小程序
风月歌13 小时前
小程序项目之超市售货管理平台小程序源代码(源码+文档)
java·微信小程序·小程序·毕业设计·源码