本篇文章给大家带来的内容是关于小程序button引导用户授权的方法介绍(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
wx-◁■△.getUserInfo(OBJECT) 注意◆☆:此接口有调整,北安市小程序制作公司使用该接口将不再出现授权弹窗●●-★,请使用
<button open-type="▽•;getUserInfo"></button>
引导用户主动进行授权操作
当用户未授权过,调用该接口将直接报错 当用户授权过☆○,可以使用该接口获取用户信息
所以我们要使用上述button来请求用户授权
1.index.wxml
<button wx:if="{{canIUse}}" open-type="…=;getUserInfo"…●☆▪; bindgetuserinfo="bindGetUserInfo" >授权登录</button>•▼; <…◇■;view wx:else>请升级微信版本<▽☆;/view>
2.index.js
Page({ data: { //判断小程序的API,回调,[上饶seo公司都选久澳]参数,虎林市小程序制作公司组件等是否在当前版本可用=•◇。 canIUse: wx•▪-.canIUse('button◇△■★.open-type.getUserInfo') }, onLoad: function () { // 查看是否授权 wx.getSetting({ success: function (res) { if (res.authSetting['scope▷◁=.userInfo']) { wx★●○☆.getUserInfo({ success: function (res) { console.log(res.userInfo) //用户已经授权过 } }) } } }) }, bindGetUserInfo: function (e) { console.log(e.detail▽▪■.userInfo) if (e◆•○□.detail△○•●.userInfo) { //用户按了允许授权按钮 } else { //用户按了拒绝按钮 } } })
注◇=▪•:如果未出现微信授权的弹窗,则可能是因为之前授权的缓存导致的,因为只有未授权才会出现弹窗-☆,清除缓存即可
本文参考:https◇•☆-://www•▪=.html.cn/study/20▼●-.html
以上就是小程序button引导用户授权的方法介绍(代码示例)的详细内容,[seo找国外公司]微信小程序开发样式设计时常见的问题整理更多请关注久澳传媒编程栏目其它相关文章!
*请认真填写需求信息,我们会在24小时内与您取得联系。