查看详细地址:uniapp登陆状态判断
1.是否登录判断(App.vue)
global.isLogin = function(){
try{
var id = uni.getStorageSync('id');
var name = uni.getStorageSync('name');
}catch(e){
//TODO handle the exception
}
if(id == '' || name == ''){
return false;
}else{
return [id, name];
}};
var res = global.isLogin();
if(!res){
uni.showModal({
title:'请登录',
content:"请登录",
success:function(){
uni.navigateTo({
url:"/pages/login"
});
}
})
}
3.登录的页面,用户登陆后储存用户信息到本地
uni.setStorageSync('id', res.data.id);
uni.setStorageSync('name', res.data.name);
网友评论