获取屏幕宽度和高度:wx.getSystemInfoSync()
创建按钮:wx.createUserInfoButton({})
例子:获取屏幕高度和宽度,作为按钮的宽高,设置按钮为透明,当用户点击之后就授权就移除按钮并获取数据,否则用户继续点击继续弹窗授权提示。
onLoad () { let sysInfo = wx.getSystemInfoSync(); // 获取微信界面大小 let screenWidth = sysInfo.screenWidth; let screenHeight = sysInfo.screenHeight; let self = this wx.login( { success: (res) => { if (res.code) { let code= res.code; console.log("登陆成功,获取到code") } var button = wx.createUserInfoButton( { type: 'text', text: '', style: { left: 0, top: 0, width: screenWidth, height: screenHeight, lineHeight: 40, backgroundColor: '#00000000', color: '#ffffff', textAlign: 'center' } }) button.onTap((res) => { if(res.errMsg=="getUserInfo:ok") { console.log("授权用户信息") //获取到用户信息 // let userInfo = res.userInfo // self.wxLogin(userInfo); wx.getUserInfo({ lang:"zh_CN", success: function(res) { let userInfo = res.userInfo console.log(userInfo) }, fail:function(){ console.log("获取失败"); return false; } }) //清除微信授权按钮 button.destroy() } else { console.log("授权失败") } }) } }) }
文章评论(0)