处理 token 过期问题

This commit is contained in:
浅念
2026-03-13 10:18:07 +08:00
parent 1fa9dfd61e
commit 4fbe2cd6b5
4 changed files with 389 additions and 3 deletions
+12 -2
View File
@@ -148,12 +148,22 @@
}
},
onLoad() {
if (!uni.getStorageSync('token')) {
// 检查是否有 token,没有则先登录
const token = uni.getStorageSync('token');
if (!token) {
// 没有 token,先登录
this.mini_login().then(() => {
this.bannerListfn()
this.$refs.paging && this.$refs.paging.reload()
}).catch(() => {
// 登录失败也加载数据(可能是游客模式)
this.bannerListfn()
this.$refs.paging && this.$refs.paging.reload()
})
}else{
} else {
// 有 token,直接加载数据
// 如果 token 过期,API 层会自动重新登录
this.bannerListfn()
this.$refs.paging && this.$refs.paging.reload()
}