Obtain user login credentials and openid in the onLaunch life cycle in app.vue
here is the code
onLaunch: function() { console.log('App Launch') uni.login({ success: function (loginRes) { // loginRes.code is the user login credentials uni.request({ url: 'backend interface', method : 'POST', dataType: 'json', header: { "content-type": "application/x-www-form-urlencoded", }, data: { code: loginRes.code, },
success: (res) => { if(res.data.code == 200) { // user openip and personal information 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);
}
})
}
});
},
The token is the obtained openid, and the specific obtained format is obtained according to the one returned by the backend