Browse Source

每次回到树生长页时,滚动位置保持上次的位置

任一存 3 years ago
parent
commit
cff96befd1
2 changed files with 11 additions and 1 deletions
  1. 3 1
      src/App.vue
  2. 8 0
      src/views/TreeAnimation.vue

+ 3 - 1
src/App.vue

@@ -4,7 +4,9 @@
       :name="transitionName"
       :mode="transitionMode"
     >
-      <router-view />
+      <keep-alive include="TreeAnimation">
+        <router-view />
+      </keep-alive>
     </transition>
   </div>
 </template>

+ 8 - 0
src/views/TreeAnimation.vue

@@ -397,11 +397,13 @@ import VisSenseFactory from 'vissense'
 const VisSense = VisSenseFactory(window)
 
 export default {
+  name: 'TreeAnimation',
   data() {
     return {
       showTree: false,
       showSlideTip: false,
       visMonitorList: [],
+      scrollTop: 0,
     }
   },
   computed: {
@@ -424,6 +426,12 @@ export default {
       visMonitor.start()
     }
   },
+  activated() {
+    this.$refs['img-wrapper'].scrollTop = this.scrollTop
+  },
+  deactivated() {
+    this.scrollTop = this.$refs['img-wrapper'].scrollTop
+  },
   destroyed() {
     for (const iterator of this.visMonitorList) {
       iterator.stop()