element-ui vue router 导航菜单刷新高亮

举例

  <el-menu
                                :default-active="onRoutes"
                                class="el-menu-vertical-demo"
                                @open="handleOpen"
                                @close="handleClose">
                            <el-menu-item index="my">
                                <i class="el-icon-setting"></i>
                                <span slot="title">

                                      <router-link to="/my" class="web-nav">我的资料</router-link>
                                </span>
                            </el-menu-item>
                            <el-menu-item index="myLoginRecord">

                                <i class="el-icon-menu"></i>
                                <span slot="title">
                                           <router-link to="/myLoginRecord" class="web-nav">登录记录</router-link>
                                    </span>

                            </el-menu-item>
                        </el-menu>

js

js里添加一个计算函数,

        computed:{
            onRoutes(){

                let path = this.$route.path.replace('/','');

                return path ? path : '/';

            }



            }

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注




Enter Captcha Here :