vue-element-admin中router-link-active怎么定义颜色
时间: 2023-07-01 16:15:48 浏览: 79
在`vue-element-admin`中,`router-link-active`是用来表示当前活动路由的类名,可以通过CSS样式来定义其颜色。具体方法如下:
1. 在`src/styles/variables.scss`中定义需要的颜色变量,例如:
```scss
$active-color: #409eff;
```
2. 在`src/styles/mixins.scss`中定义`router-link-active`样式,例如:
```scss
@mixin router-link-active {
color: $active-color;
// 下划线效果
&:after {
content: "";
display: block;
height: 2px;
background-color: $active-color;
transform: scaleX(0);
transition: transform 0.2s ease-in-out;
}
&:hover:after {
transform: scaleX(1);
}
}
```
3. 在组件中使用`router-link`,并在其上添加`v-bind:class="{ 'router-link-active': $route.path === '/your-path' }"`,例如:
```html
<router-link
v-bind:to="{ path: '/your-path' }"
v-bind:class="{ 'router-link-active': $route.path === '/your-path' }"
>
Your Route
</router-link>
```
这样,在当前路由为`/your-path`时,`router-link-active`类名会被添加到该`router-link`元素上,并且该元素的颜色会变为`$active-color`所定义的颜色。