小程式 獲取使用者基本資訊
阿新 • • 發佈:2018-12-31
Page({
data: {
nickName:'',
userInfoAvatar:'',
sex:'',
province:'',
city:''
},
onLoad: function () {
var that=this;
wx.getUserInfo({
success: function(res){
// success
that.setData({
nickName:res.userInfo.nickName,
userInfoAvatar:res.userInfo.avatarUrl,
province:res.userInfo.province,
city:res.userInfo.city
})
switch(res.userInfo.gender){
case 0:
that.setData({
sex:'未知'
})
break;
case 1:
that.setData({
sex:'男'
})
break;
case 2:
that.setData({
sex:'女'
})
break;
}
},
fail: function() {
// fail
console.log("獲取失敗!")
},
complete: function() {
// complete
console.log("獲取使用者資訊完成!")
}
})
}
})
data: {
nickName:'',
userInfoAvatar:'',
sex:'',
province:'',
city:''
},
onLoad: function () {
var that=this;
wx.getUserInfo({
success: function(res){
// success
that.setData({
nickName:res.userInfo.nickName,
userInfoAvatar:res.userInfo.avatarUrl,
province:res.userInfo.province,
city:res.userInfo.city
})
switch(res.userInfo.gender){
case 0:
that.setData({
sex:'未知'
})
break;
case 1:
that.setData({
sex:'男'
})
break;
case 2:
that.setData({
sex:'女'
})
break;
}
},
fail: function() {
// fail
console.log("獲取失敗!")
},
complete: function() {
// complete
console.log("獲取使用者資訊完成!")
}
})
}
})