From cef1f1193169a98606f6b1d95abe755e8d5df280 Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 29 Nov 2017 15:57:47 +0800 Subject: [PATCH] fix:fixed sticky component bug in keep-alive --- src/components/Sticky/index.vue | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/Sticky/index.vue b/src/components/Sticky/index.vue index 15e18f94..2c9657be 100644 --- a/src/components/Sticky/index.vue +++ b/src/components/Sticky/index.vue @@ -33,9 +33,18 @@ export default { height: undefined, child: null, stickyHeight: 0 - } }, + mounted() { + this.height = this.$el.getBoundingClientRect().height + window.addEventListener('scroll', this.handleScroll) + }, + activated() { + this.handleScroll() + }, + destroyed() { + window.removeEventListener('scroll', this.handleScroll) + }, methods: { sticky() { if (this.active) { @@ -62,13 +71,6 @@ export default { } this.reset() } - }, - mounted() { - this.height = this.$el.getBoundingClientRect().height - window.addEventListener('scroll', this.handleScroll) - }, - destroyed() { - window.removeEventListener('scroll', this.handleScroll) } }