Home >Web Front-end >uni-app >How does uniapp determine whether to log in?

How does uniapp determine whether to log in?

coldplay.xixi
coldplay.xixiOriginal
2020-12-14 11:29:1314592browse

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].

How does uniapp determine whether to log in?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn