App.vue 781 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. console.log('App Launch')
  5. this.checkLoginState()
  6. },
  7. onShow: function() {
  8. console.log('App Show')
  9. },
  10. onHide: function() {
  11. console.log('App Hide')
  12. },
  13. methods: {
  14. /**
  15. * 检查登录状态
  16. * 如果没有 token 则跳转到登录页
  17. */
  18. checkLoginState() {
  19. const token = uni.getStorageSync('user_token')
  20. if (!token) {
  21. // 未登录,跳转登录页
  22. uni.reLaunch({
  23. url: '/pages/login/login'
  24. })
  25. }
  26. // 已登录且 token 存在,保持在首页
  27. // token 过期的情况由 HTTP 拦截器处理(401/403 自动跳转登录页)
  28. }
  29. }
  30. }
  31. </script>
  32. <style>
  33. /* .uni-tabbar-border {
  34. display: none !important;
  35. } */
  36. /*每个页面公共css */
  37. </style>