當小程序抹殺掉這個接口的時候,多少人心涼了。。
作為一個初級web前端開發,我是更加懵逼,小程序員跑路了。。。
當時以及現在用的辦法就是:
1.增加一個登陸或授權頁
2.上線以后自動獲取
3.增加一個模態框
現在說說第三種吧
index.wxml

<view class='show-author' style='display:{{ismask}}'> <view class='show-author-title'> <button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo" bindtap='closeHide'>授權登錄</button> </view> </view>
index.wxss

.show-author { position: absolute; top: 0; bottom: 0; left: 0; right: 0; z-index: 99; background: #000; opacity: .7; } .show-author-title { position: absolute; top: 50%; left: 22.3%; color: #fff; } .show-author-title button { width: 200%; height: 100rpx; background-color: #ff0; line-height: 100rpx; }
index.js

closeHide:function(e){ this.setData({ ismask: 'none' }); },
index.js onload生命周期

1 wx.getSetting({ 2 success: res => { 3 if (res.authSetting['scope.userInfo']) { 4 // 已經授權,可以直接調用 getUserInfo 獲取頭像昵稱,不會彈框 5 wx.getUserInfo({ 6 success: res => { 7 this.setData({ 8 ismask: 'none' 9 }); 10 } 11 }) 12 }else{ 13 this.setData({ 14 ismask: 'block' 15 }); 16 } 17 } 18 });
很簡單吧? 載入頁面時判斷是否帶有所有權限,否則就彈出遮罩層! 通過點擊按鈕,再獲取用戶信息(不過第一次進入是要點2次。。 的確麻煩)
所以現在開發都是線下測試增加button獲取用戶信息,線上去掉button(用以前的老代碼還是會自動獲取用戶信息)
