Skip to content

FEATURE: 期望自动滚动到 高亮的菜单位置 #5944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
wyc001122 opened this issue Apr 14, 2025 · 1 comment · Fixed by #6102
Closed
3 tasks done

FEATURE: 期望自动滚动到 高亮的菜单位置 #5944

wyc001122 opened this issue Apr 14, 2025 · 1 comment · Fixed by #6102

Comments

@wyc001122
Copy link
Contributor

wyc001122 commented Apr 14, 2025

Version

Vben Admin V5

Description

当菜单(一级、二级)比较多 出现了滚动条。

第一种:如果指定的homePath 比较靠后
第二种:当前进入了比较靠后的 菜单节点,进行刷新浏览器

期望能够自动滚动到 高亮的菜单处

Proposed Solution

使用 scrollIntoView API 粗暴示意

// app.vue
onMounted(() => {
  setTimeout(() => {
    document.querySelectorAll('aside .is-active').forEach((item) => {
      item.scrollIntoView({ behavior: 'smooth' });
    });
  }, 500);
});

Alternatives Considered

No response

Additional Context

No response

Validations

  • Read the docs
  • Ensure the code is up to date. (Some issues have been fixed in the latest version)
  • I have searched the existing issues and checked that my issue does not duplicate any existing issues.
@wyc001122
Copy link
Contributor Author

wyc001122 commented Apr 17, 2025

菜单项如果比较多,点击 标签 ,也希望 左侧菜单能自动滚动到高亮处

为了防止做框架层面的大量修改,目前我暂时在 apps/web-ele/app.vue 下简单使用以下代码,实现 上述提到的 需求。

watch(
  () => route.path,
  () => {
    setTimeout(() => {
      document.querySelectorAll('aside .is-active').forEach((item) => {
        item.scrollIntoView({ behavior: 'smooth' });
      });
    }, 500);
  },
);

也许这个功能,可以做成一个偏好设置。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant