更新:登录功能
This commit is contained in:
16
hooks/usePageAuth.ts
Normal file
16
hooks/usePageAuth.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// hooks/usePageAuth.ts
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
export function usePageAuth(redirect = '/pages/login/login') {
|
||||
const store = useUserStore()
|
||||
|
||||
onShow(() => {
|
||||
if (!store.token) {
|
||||
uni.showToast({ title: '请先登录', icon: 'none' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: redirect })
|
||||
}, 800)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user