想从后台接口中获取用户信息,如下是我写的程序:

wxml:

<view class="userinfo">

    <view class='userinfo-box'>

        <block wx:for="{{uInfo}}">

            <image bindtap="" class="" src="{{item.avatarUrl}}" background-size="cover"></image>

            <view class="">{{item.nickName}}</view>

        </block>

    </view>

</view>

js:

onLoad: function () {

if (app.globalData.userInfo) {

this.setData({

userInfo: app.globalData.userInfo,

hasUserInfo: true

}),

console.log(this.data.userInfo)

wx.request({

url: 'http://api/user/1',

data: {

// nickName: this.data.userInfo.nickName,

// avatarUrl: this.data.userInfo.avatarUrl,

// gender: this.data.userInfo.gender,

// province: this.data.userInfo.province,

// city: this.data.userInfo.city,

// country: this.data.userInfo.country,

// phoneNumber: 1,

// purePhoneNumber: 2,

// countryCode: 3

},

header: {

'content-type': 'multipart/form-data' // 默认值

}, // 设置请求的 header

success: function (res) {

// success

console.log(res.data.data)

uInfo:res.data.data

},

fail: function () {

// fail

},

complete: function () {

// complete

}

})


} else if (this.data.canIUse) {

// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回

// 所以此处加入 callback 以防止这种情况

app.userInfoReadyCallback = res => {

this.setData({

userInfo: res.userInfo,

hasUserInfo: true

})

}

} else {

// 在没有 open-type=getUserInfo 版本的兼容处理

wx.getUserInfo({

success: res => {

app.globalData.userInfo = res.userInfo

this.setData({

userInfo: res.userInfo,

hasUserInfo: true

})

}

})

}

},

但是现在uInfo可以取到后台的用户信息,但是页面上显示不出来,是怎么回事呢?望大家给予解答,谢谢




展开全部
收起
5回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • 荼蘼

    15人对此回答表示赞同

    回复7:

    展开
    15
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • 爱不复生

    6人对此回答表示赞同

    你想看到结果可以这样写

    展开
    6
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • 难以启齿

    4人对此回答表示赞同

    但是我得到的是这样的结果:

    展开
    4
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • Roman抽

    1人对此回答表示赞同

    展开
    1
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • 张发宗

    1人对此回答表示赞同

    就是遍历对象而已,index是key,item是value

    展开
    1
    0回复
    发布于 6年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部