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

APP.vue

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

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

退出登录

bash 复制代码
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

bash 复制代码
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
}
相关推荐
AI多Agent协作实战派2 小时前
AI多Agent协作系统实战(二十二):从6列到12列——任务监控报告的进化之路
java·人工智能·uni-app·bug
小杨小杨、努力变强!4 小时前
VS Code运行HBuilder X中的uni-app项目
vscode·uni-app·uni-app run
码兄科技14 小时前
实战:基于Spring Boot + UniApp的地理信息小程序开发
spring boot·后端·uni-app
m0_462803881 天前
【无标题】
微信小程序
小码哥0681 天前
从三甲综合医院到连锁诊所:医院管理小程序的场景化突围逻辑(陪诊系统-陪诊APP-陪诊小程序)
小程序·医院管理系统·陪诊小程序·陪诊系统·陪诊app
2501_916007471 天前
iOS和macOS应用程序性能分析和优化工具使用综合指南
android·macos·ios·小程序·uni-app·iphone·webview
正在走向自律1 天前
用豆包Seed Evolving打造全功能【AI智能记账】小程序,开源可落地
人工智能·小程序·开源·智能记账
小羊Yveesss2 天前
模板建站哪个平台好?模板数量之外还要比较编辑与SEO能力
大数据·人工智能·小程序
2501_916007472 天前
深入理解HTTPS对称与非对称加密机制及Charles抓包实践
网络协议·http·ios·小程序·https·uni-app·iphone
郑州光合科技余经理2 天前
家政O2O平台解析:从0搭建上门预约小程序解决方案
android·java·开发语言·前端·小程序·架构·php