效果图
代码
//小程序登录
getUserProfile() {
var that = this
uni.getUserProfile({
desc: '用于登录',
success(res) {
that.userInfo = res.userInfo
uni.login({
success(res) {
if (res.code) {
uni.request({
url: getApp().globalData.url + '接口地址',
method: 'POST',
data: {
code: res.code
},
success(res) {
if (res.data.success == true) {
getApp().globalData.token = res.data.data.jwt,
uni.setStorageSync('token', getApp().globalData
.token)
that.userInfo = {
nickName: that.userInfo.nickName,
avatarUrl: that.userInfo.avatarUrl,
id: res.data.data.userInfo.id
}
uni.setStorageSync('user', that.userInfo)
}
}
})
}
}
})
}
})
}