uni.setStorageSync在登录页面设置缓存,第一次进入首页在onload里面获取不到缓存数据的解决办法

在onLoad里面获取不到缓存:
onLoad(option) {  
            const token = uni.getStorageSync('token'); 
            if(!token){
                uni.showToast({
                    title:"请先登录",
                    icon:"error",
                    mask:true
                });
                setTimeout(()=>{
                    //跳转到登录
                    uni.navigateTo({
                        url: '/pages/login/login'
                    });
                },1500);
            };
        },

在created里面就可以获取的到

created() { 
          const checkInformation = uni.getStorageSync('checkInformation');
          this.userName = checkInformation.personName;
          this.balance = checkInformation.balance;
          this.userAddress = checkInformation.projectName+'-'+checkInformation.roomName;
        },

 

posted @ 2024-01-18 12:09  make-up-xx  阅读(873)  评论(0)    收藏  举报