Skip to content
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

Update active menu item when watching the changes #6

Open
tobegit3hub opened this issue Oct 18, 2023 · 0 comments
Open

Update active menu item when watching the changes #6

tobegit3hub opened this issue Oct 18, 2023 · 0 comments
Assignees

Comments

@tobegit3hub
Copy link
Contributor

Here is the example code.

<template>
  <div>
    <a-menu :default-selected-keys="[activeMenu]" mode="vertical" theme="dark">
      <a-menu-item key="component-a">
        <router-link to="/component-a">Component A</router-link>
      </a-menu-item>
      <a-menu-item key="component-b">
        <router-link to="/component-b">Component B</router-link>
      </a-menu-item>
      <a-menu-item key="component-c">
        <router-link to="/component-c">Component C</router-link>
      </a-menu-item>
      <a-menu-item key="component-d">
        <router-link to="/component-d">Component D</router-link>
      </a-menu-item>
    </a-menu>
    <router-view />
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeMenu: 'component-a',
    };
  },
  watch: {
    $route(to, from) {
      this.activeMenu = to.name || 'component-a';
    },
  },
};
</script>
@tobegit3hub tobegit3hub self-assigned this Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant