App.vue 772 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. console.log('App Launch');
  5. interceptorInit();
  6. },
  7. onShow: function() {
  8. console.log('App Show')
  9. },
  10. onHide: function() {
  11. console.log('App Hide')
  12. },
  13. onMounted: function() {
  14. console.log('App mounted')
  15. },
  16. onUnmounted: function() {
  17. console.log('App unmounted')
  18. }
  19. }
  20. /**
  21. * 拦截器初始化
  22. */
  23. const interceptorInit = () => {
  24. uni.addInterceptor('navigateTo', {
  25. invoke(data) {
  26. const token = uni.getStorageSync('token');
  27. if (!token) {
  28. uni.reLaunch({
  29. url: "/pages/login/login"
  30. });
  31. return false; // 阻止跳转
  32. }
  33. }
  34. });
  35. }
  36. </script>
  37. <style>
  38. /*每个页面公共css */
  39. </style>