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
}
相关推荐
tcdos2 天前
不止扫码 — 微信生态深度融合(登录 + 支付 + 消息)
后端·微信小程序
小徐_23332 天前
Wot UI 2.2.0 发布:Button 新增 subtle,VideoPreview 预览体验继续增强
前端·微信小程序·uni-app
宸翰4 天前
解决 uni-app App 端 vue-i18n 占位符丢失:封装跨端可用的 tf 格式化方法
前端·vue.js·uni-app
时光足迹5 天前
uni-app 视频通话实战:康复师与患者视频问诊的 6 个致命 Bug 与解决方案
android·ios·uni-app
时光足迹5 天前
腾讯云 TRTC UniApp SDK 从入门到上线
前端·vue.js·uni-app
时光足迹5 天前
uni-app 里把加密视频嵌入页面播放?我分析了 4 种方案,只有 1 种接近完美
前端·vue.js·uni-app
时光足迹5 天前
JPush UniApp UTS 插件完全参考手册:API、事件与厂商通道一网打尽
vue.js·ios·uni-app
时光足迹5 天前
极光推送全攻略(下):uni-app 代码实现与 iOS 排查实战
vue.js·ios·uni-app
时光足迹5 天前
极光推送全攻略(上):被iOS证书折磨了三天,我写了一份前端也能看懂的避坑指南
前端·ios·uni-app
蜗牛前端5 天前
codex 全流程开发上线的高颜值礼簿小程序
前端·微信小程序