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

2019-08-02 15:49   Tags:

举例

  <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 : '/';

            }



            }

发表评论

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