Skip to content

Commit cef1f11

Browse files
committed
fix:fixed sticky component bug in keep-alive
1 parent 443c7ae commit cef1f11

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/components/Sticky/index.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@ export default {
3333
height: undefined,
3434
child: null,
3535
stickyHeight: 0
36-
3736
}
3837
},
38+
mounted() {
39+
this.height = this.$el.getBoundingClientRect().height
40+
window.addEventListener('scroll', this.handleScroll)
41+
},
42+
activated() {
43+
this.handleScroll()
44+
},
45+
destroyed() {
46+
window.removeEventListener('scroll', this.handleScroll)
47+
},
3948
methods: {
4049
sticky() {
4150
if (this.active) {
@@ -62,13 +71,6 @@ export default {
6271
}
6372
this.reset()
6473
}
65-
},
66-
mounted() {
67-
this.height = this.$el.getBoundingClientRect().height
68-
window.addEventListener('scroll', this.handleScroll)
69-
},
70-
destroyed() {
71-
window.removeEventListener('scroll', this.handleScroll)
7274
}
7375
}
7476
</script>

0 commit comments

Comments
 (0)