一、index.js設置如下
//獲取用戶的授權信息,放到本地緩存中 wx.getSetting({ success: (res) => { if(res.authSetting['scope.userInfo']) { wx.setStorage({ key: 'can_getuserinfo', data: 1, }) } else { wx.setStorage({ key: 'can_getuserinfo', data: 0, }) } } }), //1:從本地緩存中獲取數(shù)據,如果獲取到根據結果顯示Index頁面的授權按鈕是否顯示, //2:如果從本地緩存獲取不到數(shù)據則說明用戶清空了本地數(shù)據,默認設置為0,讓用戶重新授權 wx.getStorage({ key: 'can_getuserinfo', success: function (res) { console.log(res.data); that.setData({ can_getuserinfo:res.data }) },fail:function() { that.setData({ can_getuserinfo: 0 }) } }) },
二、index.wxml設置如下
<view wx:if="{{can_getuserinfo==0}}"><text>/n</text><text>/n</text><text>/n</text><button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授權登錄</button><view wx:else>請升級微信版本</view></view>
三、效果
效果是如果用戶授權過了,則直接首頁不顯示授權按鈕,直接進入業(yè)務頁面,如果用戶沒授權,則顯示授權按鈕讓用戶選擇授權
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答