feat:全局拦截器-API返回无效认证令牌时跳转登录页

This commit is contained in:
97694732@qq.com 2026-06-23 15:43:46 +08:00
parent 3a4a30511d
commit 86c326b27f

28
App.vue
View File

@ -1,7 +1,35 @@
<script> <script>
// #ifdef APP-PLUS
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
// #endif
export default { export default {
onLaunch: function() { onLaunch: function() {
console.log('App Launch') console.log('App Launch')
// API
uni.addInterceptor('request', {
success: function(res) {
if (res.data && typeof res.data === 'string') {
try {
var obj = JSON.parse(res.data)
if (obj && obj.error === '无效的认证令牌') {
uni.removeStorageSync('token')
uni.reLaunch({ url: '/pages/login/login' })
}
} catch (e) {}
} else if (res.data && res.data.error === '无效的认证令牌') {
uni.removeStorageSync('token')
uni.reLaunch({ url: '/pages/login/login' })
}
}
})
// #ifdef APP-PLUS
// onLaunch
console.log('[Upgrade] 开始检测更新...');
checkUpdate();
// #endif
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')