查看詳細(xì)地址:uniapp登陸狀態(tài)判斷
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);