vue.js - Vue + Nuxt js : How to apply dynamic active class to parent menu using bootstrap navbar

标签 vue.js nuxt.js bootstrap-vue

我是 vue + nuxt.js 的新手

我正在使用引导导航栏。看这个link

我有以下代码。

<b-nav-item-dropdown type="dark">
  <template slot="button-content">
    <i class="fas fa-user"></i> Users
  </template>
  <b-dropdown-item ref="users" to="/users" nuxt-link-active="/users">
    Listing
  </b-dropdown-item>
  <b-dropdown-item to="/users/add" nuxt-link-active="/users/add">
    Add new user
  </b-dropdown-item>
</b-nav-item-dropdown>
<b-nav-item-dropdown bg-transparent>
  <template slot="button-content">
    <i class="fas fa-users"></i> Teams
  </template>
  <b-dropdown-item to="/teams" nuxt-link-active="/teams">
    Listing
  </b-dropdown-item>
  <b-dropdown-item to="/teams/add" nuxt-link-active="/teams/add">
    Add new team
  </b-dropdown-item>
</b-nav-item-dropdown>

现在我希望在单击子项时打开父级菜单。在当前场景中,当我单击“团队列表”时,它会关闭父 div,因此无法识别打开了哪个菜单。此外,当我单击用户列表时,它应该关闭团队菜单。

我通过谷歌搜索尝试了很多方法。但找不到合适的解决方案。

最佳答案

刚刚偶然发现这个问题。如果您仍然需要的话,这是我的答案。

您不应在 Bootstrap Vue 元素中使用 nuxt-link-active

您可能更愿意使用:

<b-dropdown-item to="/teams" exact exact-active-class="active">
   Listing
</b-dropdown-item>

关于vue.js - Vue + Nuxt js : How to apply dynamic active class to parent menu using bootstrap navbar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56220715/

相关文章:

sql-server - 当结果大小太大时,使用 knex 的 SQL Server 查询会使 Nuxt 应用程序崩溃

bootstrap-vue - b-form-select 获取所选选项作为值

vue.js - 如果满足某些条件,bootstrap-vue 复选框会阻止更改

javascript - vuejs 配置 : using a global variable?

apache2 - 从 Nuxt 请求中获取当前域名

vue.js - Nuxt 如何在开发或生产中设置 baseURL

javascript - 如何在不使用 jquery 的情况下动态向引导按钮添加禁用属性

vue.js - v-on 处理程序中的错误 : "TypeError: this is null"

javascript - 使用 Vue Router 时 Pusher 和 Vue.js 组件不会离开 channel

html - 如何在CSS上的各个元素中固定按钮内文本的位置