App.vue 952 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <script>
  2. export default {
  3. onLaunch() {
  4. console.log('App Launch')
  5. },
  6. // 在页面的onShow生命周期中
  7. onShow() {
  8. // 尝试从本地存储中恢复数据
  9. const savedState = uni.getStorageSync('vuex_state');
  10. if (savedState) {
  11. this.$store.replaceState(Object.assign({}, this.$store.state, savedState));
  12. }
  13. if (this.$store.getters.user.userId) this.$chat.connect(this.$store.getters.user.userId);
  14. },
  15. // 在页面的onHide生命周期中
  16. onHide() {
  17. // 保存状态到本地存储
  18. uni.setStorageSync('vuex_state', this.$store.state);
  19. uni.removeStorageSync('chatToken');
  20. }
  21. }
  22. </script>
  23. <style lang="scss">
  24. @import "@/static/scss/common.scss";
  25. @import "@/static/font/iconfont.css";
  26. // 设置整个项目的背景色
  27. page {
  28. color: $uni-main-color;
  29. font-size: 28rpx;
  30. background: $uni-background-color;
  31. .image {
  32. width: 100%;
  33. height: 100%;
  34. }
  35. }
  36. </style>