vue根据路由变换,切换导航栏样式

            <ul>
                        <li>
                            <router-link :to="{name: 'home'}" class="active_item" exact>首页</router-link>
                        </li>
                        <li><router-link :to="{name: 'healthList'}" class="active_item">健康证办理</router-link></li>
            </ul>

1.给导航添加class属性

2.在css中定义该class对应的router-link-active样式

  .active_item.router-link-active {
        color: #358ee7;
    }

tip:

“首页”默认总是选中状态。给其后边添加一个‘exact’属性即可解决

posted @ 2019-04-15 17:09  小白&小菜  阅读(4037)  评论(0编辑  收藏  举报
我是一个小菜鸟,飞呀飞呀,快飞高