微信小程序使用按鈕獲取用戶信息
<button class="submitBtn" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">微信登錄</button>
open-type="getUserInfo" 獲取用戶信息,可以從bindgetuserinfo回調中獲取到用戶信息;
bindgetuserinfo="bindGetUserInfo" 用戶點擊該按鈕時,會返回獲取到的用戶信息,想要觸發bindgetuserinfo事件要先給button標簽添加open-type類型;
bindGetUserInfo(e){ const that=this; // 查看是否授權 wx.getSetting({ success(res) { if (res.authSetting['scope.userInfo']) { // 已經授權,可以直接調用 getUserInfo 獲取頭像昵稱 wx.getUserInfo({ success(res) { console.log(res) } }) }else{ console.log("拒絕") } } }) },