Home > Web Front-end > uni-app > body text

How does uniapp determine whether to log in?

coldplay.xixi
Release: 2023-01-13 00:44:23
Original
14478 people have browsed it

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];
 }};
Copy after login

2. Determine the page that requires login

var res = global.isLogin();
  if(!res){
   uni.showModal({
    title:'请登录',
    content:"请登录",
    success:function(){
     uni.navigateTo({
      url:"/pages/login"
     });
    }
   })
  }
Copy after 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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!