鉴权组件 auth.js
import { ComponentWithStore } from 'mobx-miniprogram-bindings'
import { userStore } from '@/stores/userStore.js'
ComponentWithStore({
data: {
isLogin: false
},
storeBindings: {
store: userStore,
fields: ['token']
},
lifetimes: {
attached() {
// 当组件被渲染时会执行的生命周期
const isLogin = !!this.data.token
if (!isLogin) {
// 获取当前全部被打开的页面实例
const pageStack = getCurrentPages()
// 最后一个页面
const lastPage = pageStack[pageStack.length - 1]
// 重定向到登录页面
wx.redirectTo({
url: `/pages/login/login/index`,
success: (res) => {
console.log(res)
},
fail: (err) => {
console.log(err)
}
})
}
}
}
})
<auth>
xxxx
</auth>
开发版工具试试
-------------------------------------------------------------------------
降低微信开发者工具版本后,该问题消失
更新 [开发版 Nightly Build (1.06.2503242)](https://developers.weixin.qq.com/miniprogram/dev/devtools/nightly.html) 后问题解决
这还是两个月前的bug, 干得漂亮! 浪费我半天时间
降版本1.06.2412040,好了