国产三级农村妇女在线,国产精品毛片a∨一区二区三区,国产乱子伦视频大全,国产精品色拉拉,国产欧美日韩一区二区三区,

首頁 > 小程序 > 小程序開發(fā)

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

小程序開發(fā) 2022-10-12 12:25:43

wx.getUserProfile接口用于微信小程序獲取用戶信息,當(dāng)頁面產(chǎn)生點(diǎn)擊事件(例如 button 上 bindtap 的回調(diào)中)后才可調(diào)用,每次請求都會彈出授權(quán)窗口,用戶同意后返回 userInfo。下面一起來看看具體的實(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ā)者每次通過該接口獲取用戶個人信息均需用戶確認(rèn)
// 開發(fā)者妥善保管用戶快速填寫的頭像昵稱,避免重復(fù)彈窗

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

},
getUserInfo(e) {

// 不推薦使用getUserInfo獲取用戶信息,預(yù)計自2021年4月13日起,getUserInfo將不再彈出彈窗,并直接返回匿名的用戶個人信息
console.log(e.detail.userInfo)
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true,
})
},
})

getUserInfo.wxml









{{userInfo.nickName}}


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

TAg

加載中~

本網(wǎng)站LOGO受版權(quán)及商標(biāo)保護(hù),版權(quán)登記號:國作登字-2022-F-10126915,未經(jīng)湖南木星科技官方許可,嚴(yán)禁使用。
Copyright ? 2012-2022 湖南木星科技有限公司(木星網(wǎng))版權(quán)所有
轉(zhuǎn)載內(nèi)容版權(quán)歸作者及來源網(wǎng)站所有,本站原創(chuàng)內(nèi)容轉(zhuǎn)載請注明來源,商業(yè)媒體及紙媒請先聯(lián)系:aishangyiwan@126.com

工信部備案號:湘ICP備19012813號-5