页面
<li class="tab-li" @click="scrollToSee(item.scrollTargetClass) " v-for="(item) in tabList" :key="item.name" :class="{'none':item.hidden,active:anchor === item.scrollTargetClass}">
{{ item.name }}
</li>
把 document.documentElement.scrollTop = Math.min(scrollTop,document.documentElement.maxScrollTop);
卸载nexttick 回调里就行了
scrollToSee(targetClassName){
let target = this.scrollTarget[targetClassName];
let currentScrollTop = document.documentElement.scrollTop;
// let tabConRect = this.tabCon.getBoundingClientRect();
let documentFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
let tabConRect = {
bottom:(documentFontSize / window.ROOT_FONT_SIZE) * (70 + 177)
};
let targetRect = target.getBoundingClientRect();
let scrollTopDelta = targetRect.top - tabConRect.bottom;
let scrollTop = currentScrollTop + scrollTopDelta;
this.$nextTick(()=>{
document.documentElement.scrollTop = Math.min(scrollTop,document.documentElement.maxScrollTop);
})
this.$router.replace({
name:this.$route.name,
params:{...this.$route.params},
query:{
anchor:targetClassName
}
})
},