hookehuyr

fix(HomePage): 修复监听activeTab变化时内容区域位置重置问题

在监听activeTab变化时,使用nextTick确保DOM更新后再执行滚动操作,以避免潜在的布局计算错误
<!--
* @Date: 2025-03-20 19:55:21
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-25 17:48:53
* @LastEditTime: 2025-03-25 17:52:17
* @FilePath: /mlaj/src/views/HomePage.vue
* @Description: 亲子学院首页组件
*
......@@ -679,13 +679,15 @@ const contentRef = ref(null) // 内容区域的ref引用
// 监听activeTab变化,重置内容区域位置
watch(activeTab, () => {
nextTick(() => {
if (contentRef.value) {
const navHeight = document.querySelector('.sticky').offsetHeight;
const marginTop = parseInt(window.getComputedStyle(contentRef.value).marginTop);
window.scrollTo({
top: contentRef.value.offsetTop - navHeight - marginTop,
behavior: 'smooth'
behavior:'smooth'
});
}
})
})
</script>
......