1、单文件应用element-plus中的Menu 侧边栏
<template>
<el-row class="tac">
<el-col :span="12">
<!-- <h5 class="mb-2">Custom colors</h5> -->
<el-menu
active-text-color="#ffd04b"
background-color="#545c64"
text-color="#fff"
class="el-menu-vertical-demo"
default-active="1"
@open="handleOpen"
@close="handleClose"
>
<el-menu-item index="1">
<router-link to="/home" class="router-link">
<el-icon><HomeFilled /></el-icon>
<span>后台首页</span>
</router-link>
</el-menu-item>
</el-menu>
</el-col>
</el-row>
</template>
如果这样写的话,会出现如下样式:(element-plus样式被打乱了)
因此,需要如下做法:
<template>
<el-row class="tac">
<el-col :span="12">
<!-- <h5 class="mb-2">Custom colors</h5> -->
<el-menu
active-text-color="#ffd04b"
background-color="#545c64"
text-color="#fff"
class="el-menu-vertical-demo"
default-active="1"
@open="handleOpen"
@close="handleClose"
>
<router-link to="/home" class="router-link">
<el-menu-item index="1">
<el-icon><HomeFilled /></el-icon>
<span>后台首页</span>
</el-menu-item>
</router-link>
</el-menu>
</el-col>
</el-row>
</template>
把router-link 放在外一层,则如下图所示:
正常显示。
2023.12.15