const app = getApp()
Page({
data: {
userInfo: {},
hasUserInfo: false
},
getUser: function (e) {
var that = this
wx.login({
success: function (res) {
if (res.code) {
wx.request({
url: 'http://localhost:8000/login',
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
data: {
code: res.code
},
success: function (rr) {
that.saveSession(rr.data)
abx()
}
})
} else {
console.log('获取用户登录状态失败!' + res.errMsg)
}
}
})
},
saveSession: function (session) {
wx.setStorage({
key: 'user_session',
data: session
})
}
})
function abx() {
console.log('这是一个全局方法!')
}