APP.vue
登陆成功后,保存登陆信息
if (res.code === 200) {
uni.setStorageSync('loginResult', res)
uni.setStorageSync('token', res.token);
uni.setStorageSync('login',false);
uni.navigateTo({
url: "/pages/learning/learning"
})
}
退出登录文章来源:https://www.toymoban.com/news/detail-632776.html
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
文章来源地址https://www.toymoban.com/news/detail-632776.html
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
}
到了这里,关于uniapp微信小程序 401时重复弹出登录弹框问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!