| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <script>
- export default {
- onLaunch: function() {
- console.log('App Launch')
- this.checkLoginState()
- },
- onShow: function() {
- console.log('App Show')
- },
- onHide: function() {
- console.log('App Hide')
- },
- methods: {
- /**
- * 检查登录状态
- * 如果没有 token 则跳转到登录页
- */
- checkLoginState() {
- const token = uni.getStorageSync('user_token')
- if (!token) {
- // 未登录,跳转登录页
- uni.reLaunch({
- url: '/pages/login/login'
- })
- }
- // 已登录且 token 存在,保持在首页
- // token 过期的情况由 HTTP 拦截器处理(401/403 自动跳转登录页)
- }
- }
- }
- </script>
- <style>
- /* .uni-tabbar-border {
- display: none !important;
- } */
- /*每个页面公共css */
- </style>
|