提取缓存中的头像地址出错

来源:2-6 感受平台生态的力量,常用API入门(下)

慕妹8003063

2021-07-01

提取缓存中的头像时,出现如下提示,头像没有显示出,而是出现两个object 。
[渲染层网络层错误] Failed to load local image resource /pages/upload/[object%20Object]
the server responded with a status of 500 (HTTP/1.1 500 Internal Server Error)
(env: Windows,mp,1.05.2106300; lib: 2.18.0)

我写的代码如下:

<view>
  <image src="{{avatar}}"></image>
  <text>{{nickname}}</text>  
</view>
onLoad: function (options) {
    const avatar=wx.getStorageInfoSync('avatar')
    const nickname=wx.getStorageInfoSync('nickname')
    // console.log(avatar)
    this.setData({
      avatar:avatar,
      nickname
    })
  },
handleUserInfo:function () {
    wx.getUserProfile({
      desc:"improve user info",
      success:(res)=>{
        console.log(res)
        const avatar=res.userInfo.avatarUrl
        const nickname=res.userInfo.nickName
        wx.setStorageSync('avatar',avatar),
        wx.setStorageSync('nickname',nickname),
        wx.navigateTo({
          url: '/pages/upload/index',
        })
      }
    })
  },

此外,执行console.log(avatar),为什么出来的不是avatar的内容,而是整个storage:
{keys: Array(3), currentSize: 1, limitSize: 10240}

麻烦老师帮忙解答一下,谢谢!

写回答

1回答

沁尘

2021-07-01

同学你好,发个代码片段上来我这边跑跑。

0
4
沁尘
回复
慕妹8003063
棒棒哒,加油
2021-07-01
共4条回复

《慕慕到家》家政小程序组件化进阶实战-优质项目

千锤百炼的实践分享,成就你独当一面

494 学习 · 306 问题

查看课程