App.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. uni.$YeIM.intoApp();
  15. this.$chat.listenerLogin();
  16. this.$chat.listenerList();
  17. },
  18. // 在页面的onHide生命周期中
  19. onHide() {
  20. // 保存状态到本地存储
  21. uni.setStorageSync('vuex_state', this.$store.state);
  22. uni.$YeIM.leaveApp();
  23. }
  24. }
  25. </script>
  26. <style lang="scss">
  27. @import "@/static/scss/common.scss";
  28. @import "@/static/font/iconfont.css";
  29. // 设置整个项目的背景色
  30. page {
  31. color: $uni-main-color;
  32. font-size: 28rpx;
  33. background: $uni-background-color;
  34. .image {
  35. width: 100%;
  36. height: 100%;
  37. }
  38. }
  39. </style>