App.vue 818 B

123456789101112131415161718192021222324252627282930
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. console.log('App Launch')
  5. },
  6. // 在页面的onShow生命周期中
  7. onShow() {
  8. // 尝试从本地存储中恢复数据
  9. const savedState = uni.getStorageSync('vuex_state');
  10. if (savedState) this.$store.replaceState(Object.assign({}, this.$store.state, savedState));
  11. if (this.$store.getters.user.userId) this.$chat.connect(this.$store.getters.user.userId);
  12. },
  13. // 在页面的onHide生命周期中
  14. onHide() {
  15. // 保存状态到本地存储
  16. uni.setStorageSync('vuex_state', this.$store.state);
  17. uni.removeStorageSync('chatToken');
  18. }
  19. }
  20. </script>
  21. <style lang="scss">
  22. /*每个页面公共css */
  23. @import '@/static/scss/common.scss';
  24. page {
  25. background-color: $uv-bg-color;
  26. font-size: 28rpx;
  27. }
  28. </style>