问题描述:
由于TabPane文字数量发生变化,TabPane宽度变化,被选中的按钮下方的指示线定位不准确,如下图:
解决后:
解决方案:
在组件中绑定ref:
<el-tabs ref="tabs"></el-tabs>
watch: {
currentLang(){
resetTabActivePosition(this.$refs.tabs.$el)
}
},
method: {
resetTabActivePosition($el) {
this.$nextTick(() => {
const activeEl = $el.querySelector('.el-tabs__item.is-active');
const lineEl = $el.querySelector('.el-tabs__active-bar');
const style = getComputedStyle(activeEl);
const pl = style.paddingLeft.match(/\d+/)[0] * 1;
const pr = style.paddingRight.match(/\d+/)[0] * 1;
const w = style.width.match(/\d+/)[0] * 1;
lineEl.style.transform = 'translateX(' + (activeEl.offsetLeft + pl) + 'px)';
lineEl.style.width = (w - pl - pr)+'px';
})
}
}