From 49e87756c70b33e1a56620ebee3c0aa53fb9fc86 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sun, 1 Nov 2020 09:57:42 +0800 Subject: [PATCH] fix(Tabs): skip initial animation --- src/tabs/index.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/tabs/index.js b/src/tabs/index.js index e9aa33450..b843f1afc 100644 --- a/src/tabs/index.js +++ b/src/tabs/index.js @@ -157,14 +157,6 @@ export default createComponent({ scrollLeftTo(nav, to, immediate ? 0 : +props.duration); }; - const init = () => { - nextTick(() => { - state.inited = true; - tabHeight = getVisibleHeight(wrapRef.value); - scrollIntoView(true); - }); - }; - // update nav bar style const setLine = () => { const shouldAnimate = state.inited; @@ -385,11 +377,13 @@ export default createComponent({ watch( () => children.length, () => { - nextTick(() => { + if (state.inited) { setCurrentIndexByName(props.active || currentName.value); setLine(); - scrollIntoView(true); - }); + nextTick(() => { + scrollIntoView(true); + }); + } } ); @@ -408,6 +402,15 @@ export default createComponent({ } ); + const init = () => { + setCurrentIndexByName(props.active || currentName.value); + nextTick(() => { + state.inited = true; + tabHeight = getVisibleHeight(wrapRef.value); + scrollIntoView(true); + }); + }; + onMounted(init); onActivated(() => {