0

我有一个包含多个像这样的侧边栏项目的侧边栏

<side-bar>
    <template slot="links">

        <sidebar-item  :link="{name: 'Home', icon: 'ni ni-shop text-primary', path: '/dashboard'}" />
        <sidebar-item  :link="{name: 'Videos', icon: 'ni ni-tv-2 text-primary', path: '/videos'}"/>
        <sidebar-item  :link="{name: 'Category', icon: 'ni ni-single-copy-04 text-primary', path: '/category'}"/>
        <sidebar-item  :link="{name: 'Comments', icon: 'ni ni-ambulance text-primary', path: '/comments'}"/>
        <sidebar-item  :link="{name: 'Artist', icon: 'ni ni-palette text-primary', path: '/artists'}"/>
        <sidebar-item  :link="{name: 'Users', icon: 'ni ni-circle-08 text-primary', path: '/users'}"/>
        <sidebar-item  :link="{name: 'Transactions', icon: 'ni ni-credit-card text-primary', path: '/transactions'}"/>

    </template>
</side-bar>

侧边栏项目有这样的路由器链接

<li class="nav-item bg-white">
<router-link
  :to="link.path"
  @click.native="linkClick"
  class="nav-link"
  :target="link.target"
  :href="link.path"
>
  <template>
      <i :class="link.icon"></i>
      <span class="nav-link-text">{{ link.name }}</span>
  </template>
</router-link>

路由器配置有linkExactActiveClass: 'active',

我应该怎么做才能在此处设置活动侧边栏项目的样式

4

1 回答 1

0

router-link一个属性active-class,允许您在该元素处于活动状态时在该元素上创建一个类,例如:

<router-link
        active-class="nav__active"
        to="/something"
        class="header__nav"
      > Something
</router-link>

在你的styles

.header__nav{
    ....
}
.nav__active{
    /* your styles for the active link */
}

让我知道这是否是您正在寻找的

于 2021-07-24T11:07:59.230 回答