温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

elementUI中MENU菜单的坑怎么解决

发布时间:2022-04-06 13:55:54 来源:亿速云 阅读:235 作者:iii 栏目:开发技术

这篇文章主要介绍了elementUI中MENU菜单的坑怎么解决的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇elementUI中MENU菜单的坑怎么解决文章都会有所收获,下面我们一起来看看吧。

需求:点击当前页面的按钮跳转到首页,给menu中绑定的default-active赋值

问题:页面已经跳转过去,可menu选中项根本没有发生变化

解决办法: 直接将当前页面的路由绑定到default-active上,同时将index改为当前路由,这样在通过非点击导航菜单跳转页面时就不需要再来手动改变导航菜单的选中项了,它会自己选中当前页面的tab项,完美解决!

说明:router属性很重要,default-active="this.$route.path"也很重要。

<el-menu
        :router="true"
        :default-active="$route.name"
        class="el-menu-demo"
        mode="horizontal"
        @select="select"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b">
            <el-menu-item :route="{name: 'home'}" index="home">
                <template slot="title">
                    <Icon type="ios-home"></Icon>
                    <span>首页</span>
                </template>
            </el-menu-item>
            
            <el-menu-item :route="{name: 'article'}" index="article">
                <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>文章</span>
                </template>
            </el-menu-item>
 
            <el-menu-item :route="{name: 'time'}" index="time">
                <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>时间轴</span>
                </template>
            </el-menu-item>
            
            <el-menu-item :route="{name: 'photo'}" index="photo">
                <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>生活照</span>
                </template>
            </el-menu-item>
            
            <el-menu-item :route="{name: 'footprint'}" index="footprint">
                <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>足迹</span>
                </template>
            </el-menu-item>
            
            <el-menu-item :route="{name: 'aboutme'}" index="aboutme">
                <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>关于我</span>
                </template>
            </el-menu-item>
 
            <el-menu-item :route="{name: 'message'}" index="message">
                <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>留言板</span>
                </template>
            </el-menu-item>
            <el-menu-item :route="{name: 'manage'}" index="manage">
                <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>后台管理</span>
                </template>
            </el-menu-item>
    </el-menu>

关于“elementUI中MENU菜单的坑怎么解决”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“elementUI中MENU菜单的坑怎么解决”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI