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

},

},

},

},

)

相关推荐
爱学习 爱分享13 小时前
微信小程序html 在 webview 会打开再缩放一下
微信小程序·小程序·html
梦梦代码精14 小时前
深度拆解:上门按摩系统如何成为本地生活“到家时代”的新引擎?
docker·小程序·uni-app·开源·生活·开源软件
Geek_Vison16 小时前
如何借助小程序容器技术实现跨端APP的敏捷开发
小程序·apache·敏捷流程
xshirleyl16 小时前
微信小程序开发week6-慕尚花坊项目
微信小程序·小程序
usdoc文档预览16 小时前
国产化踩坑:Vue3 / React / 小程序如何免插件实现 OFD 及复杂 Office 文档同屏预览
前端·javascript·react.js·小程序·pdf·word·office文件在线预览
倒流时光三十年16 小时前
第二章 小程序目录结构与核心文件详解
spring boot·小程序
好赞科技18 小时前
2026年八大上门服务预约小程序:解锁高效生活新体验
大数据·微信小程序
维双云18 小时前
从零到一:一份关于“做小程序的步骤”的完整实操指南
小程序
编程猪猪侠18 小时前
uni-app微信小程序车牌号输入组件实现
微信小程序·uni-app
客场消音器1 天前
如何使用codex进行UI重构,让AI开发的前端页面不再千篇一律
前端·后端·微信小程序