From e67b4d54033fe5e1eeda3c67fb11f1c96d31e09d Mon Sep 17 00:00:00 2001 From: jiaming743 <743192023@qq.com> Date: Wed, 19 Aug 2020 19:25:25 +0800 Subject: [PATCH] Optimize the update effect of updateRows. --- src/components/scrollBoard/src/main.vue | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/scrollBoard/src/main.vue b/src/components/scrollBoard/src/main.vue index d52ff12..70511e3 100644 --- a/src/components/scrollBoard/src/main.vue +++ b/src/components/scrollBoard/src/main.vue @@ -178,7 +178,9 @@ export default { animationHandler: '', - updater: 0 + updater: 0, + + needCalc: false } }, watch: { @@ -335,6 +337,14 @@ export default { this.aligns = deepMerge(aligns, align) }, async animation (start = false) { + const { needCalc, calcHeights, calcRowsData } = this + + if (needCalc) { + calcRowsData() + calcHeights() + this.needCalc = false + } + let { avgHeight, animationIndex, mergedConfig, rowsData, animation, updater } = this const { waitTime, carousel, rowNum } = mergedConfig @@ -389,15 +399,15 @@ export default { }) }, updateRows(rows, animationIndex) { - const { mergedConfig, calcRowsData, calcHeights, animationHandler, animation } = this + const { mergedConfig, animationHandler, animation } = this this.mergedConfig = { ...mergedConfig, data: [...rows] } - calcRowsData() - calcHeights() + this.needCalc = true + if (typeof animationIndex === 'number') this.animationIndex = animationIndex if (!animationHandler) animation(true) }