App.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <script>
  2. import Vue from 'vue'
  3. import config from '@/config.js'
  4. Vue.prototype.$config = config
  5. export default {
  6. onLaunch: function(options) {
  7. console.log('App Launch', options)
  8. // 从 storage 恢复登录态到 store,保证 state 与 storage 一致
  9. this.$store.dispatch('restore')
  10. },
  11. onShow: function(options) {
  12. console.log('App Show', options)
  13. // 热启动兜底:若 store 空但 storage 有 token(如 HBuilderX 热更新后 store 重置),重新恢复
  14. if (!this.$store.state.token && uni.getStorageSync('token')) {
  15. this.$store.dispatch('restore')
  16. }
  17. },
  18. onHide: function() {
  19. console.log('App Hide')
  20. }
  21. }
  22. </script>
  23. <style>
  24. page {
  25. background-color: #F5F5F5;
  26. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI',
  27. 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
  28. 'Helvetica Neue', Helvetica, Arial, sans-serif;
  29. color: #1E293B;
  30. font-size: 28rpx;
  31. line-height: 1.6;
  32. -webkit-font-smoothing: antialiased;
  33. }
  34. .page {
  35. padding: 0 32rpx 32rpx;
  36. min-height: 100vh;
  37. }
  38. .safe-area-bottom {
  39. padding-bottom: calc(constant(safe-area-inset-bottom) + 20rpx);
  40. padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
  41. }
  42. </style>