html52.com
我爱小程序-开发者交流社区

wx.setStorage设置和读取缓存是否考虑一次性多个?

//登陆成功后把用户的昵称和 头像保存到缓存里面
wx.setStorage({
 key: "denglu", data: "true"
})
wx.setStorage({
  key: "nickName", data: e.detail.userInfo.nickName
 })
 
wx.setStorage({
  key: "avatarUrl", data: e.detail.userInfo.avatarUrl
 })
//打印刚刚charity的缓存看看
wx.getStorage({
  key: 'denglu',
  success: function (res) {
    console.log("登陆缓存" + res.data)
  }
})
 
wx.getStorage({
  key: 'avatarUrl',
  success: function (res) {
    console.log("avatarUrl缓存" + res.data)
  }
})
 
wx.getStorage({
  key: 'nickName',
  success: function (res) {
    console.log("nickName缓存" + res.data)
  }
})


每设置和读取一次缓存就必须写一个方法,

能不能考虑,一次性设置或者读取多个参数,尽量简化代码?

网友回复

undefined:

.......无语啊,干嘛不直接存一个对象

wx.setStorage({
  key: "userInfo", data: e.detail.userInfo

 });

//获取

var name=wx.getStorageSync("userInfo").nickName


卢霄霄:

存个 JSON.stringify(userInfo) 如何

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付