注意:此接口有调整,使用该接口将不再出现授权弹窗,请使用 引导用户主动进行授权操作 做了一个小demo记录一下 小程序官网介绍
template open-type ="getUserInfo" @getuserinfo="bindGetUserInfo" @click="getUserInfo1" >获取权限
script onload(){},mounted(){this.getSetting()},methods: {getSetting(){wx.getSetting({success: function (res ){if (res.authSetting['scope.userInfo' ]) {wx.getUserInfo({success: function (res ) { console.log (res.userInfo)console.log ('用户已经授权过' )}})}else {console.log ('用户还未授权过' )}}})},getUserInfo1(){console.log ('click事件首先触发' )if (wx.canIUse('button.open-type.getUserInfo' )){}else {console.log ('请升级微信版本' )}},bindGetUserInfo(e) {if (e.mp.detail.rawData){console.log ('用户按了允许授权按钮' )} else {console.log ('用户按了拒绝按钮' )}},