element-plus [Component] [menu] Menu default-active attribute bug

vc9ivgsu  于 5个月前  发布在  其他
关注(0)|答案(4)|浏览(97)

Bug Type: Component

Environment

  • Vue Version: 3.2.45
  • Element Plus Version: 2.2.22
  • Browser / OS: Chrome
  • Build Tool: Vite

Reproduction

  • el-menu

Element Plus Playground

Steps to reproduce

Based on this thread: #8848

I have a menu like this:

<el-menu
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
:router="true"
:default-active="$route.path"

<el-menu-item index="1">Processing Center</el-menu-item>
<el-sub-menu index="2">
  <template #title>Workspace</template>
  <el-menu-item index="2-1">item one</el-menu-item>
  <el-menu-item index="2-2">item two</el-menu-item>
  <el-menu-item index="2-3">item three</el-menu-item>
  <el-sub-menu index="2-4">
    <template #title>item four</template>
    <el-menu-item index="2-4-1">item one</el-menu-item>
    <el-menu-item index="2-4-2">item two</el-menu-item>
    <el-menu-item index="2-4-3">item three</el-menu-item>
  </el-sub-menu>
</el-sub-menu>

When I route to localhost/1, localhost/2-1, localhost/2-4-2 etc. everything works prefect. BUT when I route to localhost/1 (first menu activated, fine) then I navigate to localhost/something none of the menu item will be activated. localhost/something has no menu item, as it is just some sub route for localhost/1 what doesn't need own menu item. The last activated menu item should keep its activated state.

There should be an option to keep last active menu index if there is no matching menu item index for current route.

Please advice,
Lajos

What is Expected?

If we use router for display active menu item, if there is no matching menu item index for current route the previous matching active menu item should keep active.

What is actually happening?

None of menu item will be active after we route to a new route without menu item matching index.

Additional comments

(empty)

7gyucuyw

7gyucuyw1#

我也遇到类似的问题,路由切换了,但是默认的样式并没有改变,第一次是成功的,后面就不行了。甚至是错乱的;
查看了源代码,菜单切换后,路由跳转,但是菜单的is-active样式并不匹配,一般是上一个。同时还会展开关闭的菜单。

3duebb1j

3duebb1j2#

我也遇到了一样的问题

gywdnpxw

gywdnpxw4#

经过测试,在el-menu的select事件中执行router.push({ path: key })路由变化后会触发这个bug

相关问题