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
}
相关推荐
m0_462803885 小时前
“趣味运动会记分”功能教学指南
小程序
网络安全学习库9 小时前
很喜欢Vue,但还是选择了React: AI时代的新考量
vue.js·人工智能·react.js·小程序·aigc·产品经理·ai编程
叱咤少帅(少帅)10 小时前
Uniapp开发pc端,小程序和APK
小程序·uni-app
2501_915918411 天前
iOS性能测试工具 Instruments、Keymob的使用方法 不局限 FPS
android·ios·小程序·https·uni-app·iphone·webview
Chengbei111 天前
利用 LibreNMS snmpget 配置篡改实现 RCE 的完整攻击链
人工智能·web安全·网络安全·小程序·系统安全
苏灵凯1 天前
智能环境监测终端全栈设计:从单片机到微信小程序,手把手搞定!
单片机·嵌入式硬件·mcu·物联网·微信小程序·小程序·蓝牙模块
nhc0881 天前
贵阳纳海川科技有限公司・货运物流行业解决方案
科技·微信小程序·小程序·软件开发·小程序开发
admin and root1 天前
AWS S3 对象存储攻防&云安全之OSS存储桶漏洞
微信小程序·小程序·渗透测试·云计算·aws·src·攻防演练
取码网1 天前
新版点微同城主题源码34.7+全套插件+小程序前后端 源文件
小程序
2501_915918411 天前
iOS 混淆流程 提升 IPA 分析难度 实现 IPA 深度加固
android·ios·小程序·https·uni-app·iphone·webview