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(() => {