uniapp微信小程序 401时重复弹出登录弹框问题

APP.vue
uniapp微信小程序 401时重复弹出登录弹框问题_第1张图片

登陆成功后,保存登陆信息

if (res.code === 200) {
	
	uni.setStorageSync('loginResult', res)
	uni.setStorageSync('token', res.token);
	uni.setStorageSync('login',false);
	uni.navigateTo({
		url: "/pages/learning/learning"
	})
}

退出登录

toLogout: function() {
	uni.showModal({
		title: "确认退出登录吗",
		content: "",
		confirmText: "确定",
		showCancel: true,
		success: (res) => {
			if (res.confirm) {
				uni.showLoading();
				var params = {
					url: "/user/logout",
					method: "DELETE",
					data: {},
					callBack: res=> {
						uni.hideLoading()
						console.log(res)
						uni.removeStorageSync('loginResult');
						uni.removeStorageSync('token');
						uni.removeStorageSync('hadLogin');
						uni.removeStorageSync('code');
						uni.removeStorageSync('login');
						uni.navigateTo({
							url:"/pages/login/login"
						})
					}
				};
				http.request(params);
			}
		}
	})	
}

http.js
uniapp微信小程序 401时重复弹出登录弹框问题_第2张图片

if(res.data.code == 401){
	uni.hideLoading();
	
	if(!uni.getStorageSync('login')){
		uni.setStorageSync('login',true);
		uni.showModal({
			title: '提示',
			content: '登录已过期,请重新登陆!',
			cancelText: "取消",
			confirmText: "确定",
			success: function (res) {
				if (res.confirm) {
					uni.removeStorageSync('loginResult');
					uni.removeStorageSync('token');
					uni.removeStorageSync('hadLogin');
					uni.removeStorageSync('code');
					
					uni.navigateTo({
						 url: '/pages/login/login'
					})
				} else if (res.cancel) {
					
				}
			}
		});
	}					
	return
}

你可能感兴趣的:(uni-app,微信小程序,小程序)