我明明用了 setStorageSync,为什么缓存中没有数据?哭了
发布于 3 年前 作者 wangming 1273 次浏览 来自 问答
Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUseGetUserProfile: false,
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
    // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
      success: (res) => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
        console.log(res);
        const{userInfo} = e.detail;
        wx.setStorageSync('userInfo', userInfo);
        wx.navigateTo({
          url: '/pages/users/users',
        })  
      },
    })}})


2 回复
你先打印userInfo有没有值再说
回到顶部