在app.vue里面onLaunch生命周期里面获取用户登录凭证及openid
一下为代码
onLaunch: function() {
console.log('App Launch')
uni.login({
success: function (loginRes) {
// loginRes.code为用户登录凭证
uni.request({
url: '后端接口',
method: 'POST',
dataType: 'json',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
code: loginRes.code,
},
success: (res) => {
if(res.data.code == 200) {
// 用户openip及个人信息
uni.setStorageSync('token', res.data.data.token);
uni.setStorageSync('userinfo', res.data.data.userinfo);
} else {
uni.showToast({
icon:'none',
title:String(res.data.msg)
})
}
},
fail: function(e) {
console.log(22222);
}
})
}
});
},
token就是获取到的openid,具体获取的格式按后端返回的来拿