欧美日韩中文一区二区,亚洲天堂av在线,亚洲最大成人免费视频,欧美最新精品

微信小程序wx.getUserProfile接口獲取用戶昵稱、頭像

wx.getUserProfile接口用于微信小程序獲取用戶信息,當(dāng)頁(yè)面產(chǎn)生點(diǎn)擊事件(例如 button 上 bindtap 的回調(diào)中)后才可調(diào)用,每次請(qǐng)求都會(huì)彈出授權(quán)窗口,用戶同意后返回 userInfo。下面一起來(lái)看看具體的實(shí)現(xiàn)方法吧:

getUserInfo.js

Page({
data: {
userInfo: {},
hasUserInfo: false,
canIUseGetUserProfile: false,
},
onLoad() {
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
getUserProfile(e) {
// 推薦使用wx.getUserProfile獲取用戶信息,開發(fā)者每次通過該接口獲取用戶個(gè)人信息均需用戶確認(rèn)
// 開發(fā)者妥善保管用戶快速填寫的頭像昵稱,避免重復(fù)彈窗

wx.getUserProfile({
desc: '用于完善會(huì)員資料', // 聲明獲取用戶個(gè)人信息后的用途,后續(xù)會(huì)展示在彈窗中,請(qǐng)謹(jǐn)慎填寫
success: (res) => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
console.log(res.userInfo)
}
})

},
getUserInfo(e) {

// 不推薦使用getUserInfo獲取用戶信息,預(yù)計(jì)自2021年4月13日起,getUserInfo將不再?gòu)棾鰪棿?amp;#xff0c;并直接返回匿名的用戶個(gè)人信息
console.log(e.detail.userInfo)
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true,
})
},
})

getUserInfo.wxml

<view class=”container”>
<view class=”userinfo”>
<block wx:if=”{{!hasUserInfo}}”>
<button wx:if=”{{canIUseGetUserProfile}}” bindtap=”getUserProfile”> 獲取頭像昵稱 </button>
<button wx:else open-type=”getUserInfo” bindgetuserinfo=”getUserInfo”> 獲取頭像昵稱 </button>
</block>
<block wx:else>
<image bindtap=”bindViewTap” class=”userinfo-avatar” src=”{{userInfo.avatarUrl}}” mode=”cover”></image>
<text class=”userinfo-nickname”>{{userInfo.nickName}}</text>
</block>
</view>
</view>

微信小程序wx.getUserProfile接口獲取用戶昵稱、頭像具體信息,小程序開發(fā)者可以參考官方文檔:https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html


聲明:本站部分文章來(lái)源于互聯(lián)網(wǎng),如有侵犯作者著作權(quán),請(qǐng)及時(shí)與我們聯(lián)系。

木魚小鋪小程序

為您推薦

主站蜘蛛池模板: 木里| 忻城县| 化州市| 大同市| 海盐县| 日照市| 大冶市| 迁西县| 海安县| 绵阳市| 汨罗市| 龙川县| 普安县| 陇川县| 南岸区| 丽江市| 渑池县| 无棣县| 黑龙江省| 朝阳县| 岑巩县| 汤阴县| 巴林右旗| 山西省| 陆良县| 修水县| 西畴县| 临安市| 榆中县| 山东省| 韩城市| 阿合奇县| 调兵山市| 桂林市| 南城县| 抚松县| 旌德县| 随州市| 祁门县| 肥乡县| 化隆|