App.vue 646 B

123456789101112131415161718192021222324252627282930313233343536
  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. }
  14. /**
  15. * 拦截器初始化
  16. */
  17. const interceptorInit = () => {
  18. uni.addInterceptor('navigateTo', {
  19. invoke(data) {
  20. const token = uni.getStorageSync('token');
  21. if (!token) {
  22. uni.reLaunch({
  23. url: "/pages/login/login"
  24. });
  25. return false; // 阻止跳转
  26. }
  27. }
  28. });
  29. }
  30. </script>
  31. <style>
  32. /*每个页面公共css */
  33. </style>