如果登录过期了,我请求的接口有3个它会弹三次登录过期弹窗
我也遇到了这个问题
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
有解决了吗?
我的原因是因为启用了二级路径,但在后台中没有配置相应的路径引起的。
完整代码:
// 使用防抖函数控制弹窗的执行次数
debounce(() => {
isLoginExpiredDialogShown = true;
uni.hideLoading();
showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
if (res.confirm) {
isLoginExpiredDialogShown = false;
store.dispatch('LogOut').then(res => {
uni.redirectTo({
url: '/pages/login'
})
})
}
})
}, 500)();
// 防抖
function debounce(func, wait) {
let timeout;
return function () {
const context = this;
const args = arguments;
clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = null;
func.apply(context, args);
}, wait);
};
}
测试了一下H5 和小程序,调用两个接口,清空缓存数据,登录过期只会弹出一个,没有你说的问题,
无法复现的问题,请提供具体的步骤和相关能复现问题的全部示例代码。
示例代码:
onLoad(){
/**
* 此时每个请求都返回401
* 此时这三个请求都到达 request.js中的 if(code === 401) 中
* if(code === 401) 中的代码执行 三遍
*/
this.demo1();
this.demo2();
this.demo3();
},
methods:{
demo1(){
request(...).then();
},
demo2(){
request(...).then();
},
demo3(){
request(...).then();
}
}
我就是这么测试的,以个人中心为例,并没有出现三次,你可以提供真实复现示例代码出来看看。
<template>
<view class="container">
<uni-list>
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'person-filled'}" title="昵称" :rightText="user.nickName" />
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'phone-filled'}" title="手机号码" :rightText="user.phonenumber" />
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'email-filled'}" title="邮箱" :rightText="user.email" />
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'auth-filled'}" title="岗位" :rightText="postGroup" />
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'staff-filled'}" title="角色" :rightText="roleGroup" />
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'calendar-filled'}" title="创建日期" :rightText="user.createTime" />
</uni-list>
</view>
</template>
<script>
import { getUserProfile } from "@/api/system/user"
export default {
data() {
return {
user: {},
roleGroup: "",
postGroup: ""
}
},
onLoad() {
this.getUser()
this.getUser()
this.getUser()
},
methods: {
getUser() {
getUserProfile().then(response => {
this.user = response.data
this.roleGroup = response.roleGroup
this.postGroup = response.postGroup
})
}
}
}
</script>
<style lang="scss">
page {
background-color: #ffffff;
}
</style>
在request.js中拦截到了401的话就会让你选择是否登出,选择了是的话,会去调用登出接口,但是登出接口也返回401的话就又会被request.js拦截,导致一直卡住
登录 后才可以发表评论