APP 项目,登录注册页面,注意事项


要在登录成功之后,运用销毁当前页面,跳到别的页面

setTimeout(()=>{
                            
        uni.reLaunch({
                 url: '/pages/index/index'
                });
    },2000)


除了 要注意 登录和注册页面的 非空验证外,还需注意:账户 如果登录了,退出app后,再进入,无需 再次进行登录操作  在 index 页面操作

mounted() {
        if(uni.getStorageSync('token')){//已经有登录状态了
            
        }else{
            uni.reLaunch({
                url:'/pages/login/login'
            })
        }
    },
在登录成功后,要把一些信息,放到缓存,存起来,方便 接下来的接口调用等

this.$http.url_Request('/app_api/home/member/login.json',params,'POST',true).then( res => {
                    if(res.success) {
                        uni.setStorageSync('phone', this.register_phone);
                        uni.setStorageSync('token', res.data.token);
                        uni.setStorageSync('userid', res.data.id);
                        console.log('登录成功')
                        uni.showToast({
                            title:'登录成功',
                            duration:2000
                        }),
                        setTimeout(()=>{
                            // uni.navigateTo({
                            //     url: '/pages/index/index'
                            // })
                            uni.reLaunch({
                                url: '/pages/index/index'
                            });
                        },2000)
                        
                    }else {
                        uni.showToast({
                            icon:'none',
                            title:res.msg,
                            duration:2000
                        })
                        this.$toast(res.msg,'none')
                    }
                })
原文地址:https://www.cnblogs.com/kanchai/p/14006049.html