uni-app登陆状态判断
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]; }};
2.需要登录的页面判断
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);