vue router-link路由跳转时切换导航栏样式

465 阅读1分钟

router-link路由跳转切换导航栏样式

  • 在css中定义该class对应的router-link-active样式
  • 设置首页为默认状态:添加exact属性

左右布局 高度撑满屏幕 高度超出显示内部滚动条

<template>
    <div class="container">
        <div class="countLeft">
            <ul class="nav">
                <li>
                    <router-link to="/checkbox" exact>
                        el-checkbox-group表格外部的全选/反选
                    </router-link>
                </li>
                <li>
                    <router-link to="/imgCropper">imgCropper</router-link>
                </li>
            </ul>
        </div>
        <div class="countRight">
            <router-view class="main"></router-view>
        </div>
    </div>
</template>
<style scroped>
.container {
    margin:20px;
    display: flex;
}
.clearfix:after{content:""; display:block; clear:both; height:0; visibility:hidden; }
.countLeft {
    width:310px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 10px;
    box-sizing: border-box;
    border: 1px solid #d7dfe3;
    border-radius:10px;
    background-color: #fff;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,.1), 0 3px 10px -5px hsla(0,0%,60%,.4);
}
.countRight {
    flex: 1;
    width: 100%;
    min-height: calc(100vh - 40px);
    margin-left: 15px;
    padding: 20px;
    box-sizing: border-box;
    border: 1px solid #d7dfe3;
    border-radius:10px;
    background-color: #fff;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,.1), 0 3px 10px -5px hsla(0,0%,60%,.4);
}
.nav li { min-height: 30px; }
.nav li .router-link-active { color: #409eff; }
</style>