// 授权手机号 需要button标签 注意:open-type 的值 必须是getPhoneNumber <button open-type="getPhoneNumber" bindgetphonenumber="getuserinfo">授权登录</button> getuserinfo (e) { let that = this if (e.detail.errMsg.indexOf("getPhoneNumber:ok") > -1) { // 授权成功 通过login 获取code 提交服务端 进行解密 解密的参数为 data wx.login({ success: res => { if (res.code) { let data = { encryptedData: e.detail.encryptedData, iv: e.detail.iv, code: res.code } }) } else { wx.showToast({ title: '授权失败,请重新授权!', icon: 'none', duration: 2000 }) } }
// 获取基础信息 需要button标签 设置 open-type 为 getUserInfo <button open-type="getUserInfo" bindgetuserinfo="getuserinfo">授权基础信息</button> getuserinfo(res) { var self = this if (res.detail.errMsg.indexOf("getUserInfo:ok") > -1) { console.log(res.detail.userInfo) } else { wx.showToast({ title: '授权失败,请重新授权!', icon: 'none', duration: 2000 }) } }
onShareAppMessage (res) { console.log(res) return { title: title, imageUrl: imageUrl, path: '/pages/hotinfo/hotinfo?articleCode=' + articleCode, success: function(res) { // 无法监听到返回函数 } } }, })
const query = wx.createSelectorQuery() query.select('#the-id').boundingClientRect() query.selectViewport().scrollOffset() query.exec(function(res){ consoel.log(res) })