Uniapp's method of determining whether to log in: 1. Determine the page that requires login, the code is [uni.showModal({title:'Please log in', content: "Please log in",]; 2. After the user logs in After storing the user information locally, the code is [uni.setStorageSync].
The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, thinkpad t480 computer.
Recommended (free): uni-app development tutorial
##uniapp determines whether to log in Method:
1. Determine whether to log in (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. Determine the page that requires login
var res = global.isLogin(); if(!res){ uni.showModal({ title:'请登录', content:"请登录", success:function(){ uni.navigateTo({ url:"/pages/login" }); } }) }
3. On the login page, after the user logs in, the user information is stored locally
uni.setStorageSync('id', res.data.id); uni.setStorageSync('name', res.data.name);
Related free learning recommendations:php programming (video )
The above is the detailed content of How does uniapp determine whether to log in?. For more information, please follow other related articles on the PHP Chinese website!