最简单的写法,引入$route.path 如果报错先引入定义
:default-active="$route.path"
<el-menu
class="el-menu-vertical-demo"
:collapse="homeStore.isCollapse"
background-color="#001529"
text-color="white"
active-text-color="yellowgreen"
:router="trueValue"
:default-active="$route.path"
@select="handleSelect"
>
vue3
<script setup>
import { appSource } from '../../utils/app.js'
import { Calendar, Timer, TakeawayBox } from '@element-plus/icons-vue'
import { useRouter, useRoute } from 'vue-router'
import { onMounted, ref, watch } from 'vue'
let $route = useRoute()
const trueValue = ref(true)
console.log(appSource)
let activeIndex = ref('')
let activePath = ref('/1