点击的时候需要双重视图滚动
itemClick(id) {
// 滚动到对应位置
this.$nextTick(() => {
// 找到对应 id 在 initList2 中的索引
const index = this.initList2.findIndex(
(item) => item.id === Number(id)
);
if (index !== -1) {
// 获取所有菜单项
const menuItems = document.querySelectorAll(".wanfa .el-menu-item");
if (menuItems[index]) {
// 滚动到视图
menuItems[index].scrollIntoView({
behavior: "smooth",
block: "center",
});
// 触发选择事件
this.handleSelect2(id.toString());
// 添加高亮样式
menuItems[index].click();
}
}
});
},
在这里插入代码片