From 097b2670d77e1cb859735ee75054a314ce6e05fe Mon Sep 17 00:00:00 2001 From: jiaming <743192023@qq.com> Date: Sat, 8 Dec 2018 19:16:30 +0800 Subject: [PATCH] optmization for update data --- src/components/scrollBoard/index.vue | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/scrollBoard/index.vue b/src/components/scrollBoard/index.vue index 1a74fb8..bce06df 100644 --- a/src/components/scrollBoard/index.vue +++ b/src/components/scrollBoard/index.vue @@ -33,19 +33,22 @@ export default { }, watch: { data () { - const { init } = this + const { init, autoScrollHandler } = this + + this.fade = false + this.currentTopIndex = 0 + + autoScrollHandler && clearTimeout(autoScrollHandler) init() } }, methods: { init () { - const { data, autoScrollHandler, getDealAfterData, getCurrentScrollData } = this + const { data, getDealAfterData, getCurrentScrollData } = this if (!data) return - autoScrollHandler && clearTimeout(autoScrollHandler) - getDealAfterData() getCurrentScrollData() @@ -68,14 +71,14 @@ export default { this.scrollData = tempArray - setTimeout(doFade, 1500) + this.autoScrollHandler = setTimeout(doFade, 1500) }, doFade () { const { reGetCurrentScrollData } = this this.fade = true - setTimeout(reGetCurrentScrollData, 1500) + this.autoScrollHandler = setTimeout(reGetCurrentScrollData, 1500) }, reGetCurrentScrollData () { const { getCurrentScrollData, dealAfterData, currentTopIndex } = this