vue cli+element ui顶部导航栏切换

vue cli+element ui顶部导航栏切换

效果

在这里插入图片描述

实现

表单样式

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

<el-menu
    :default-active="this.$route.path"
     class="el-menu-demo"
     mode="horizontal"
     @select="handleSelect"
     router
     background-color="#fff"
     text-color="#333"
     active-text-color="#0084ff"
     >
     <el-menu-item v-for="(item,i) in navList" :key="i" :index="item.name">
          <template slot="title">
             <span> {{ item.navItem }}</span>
          </template>
     </el-menu-item>
</el-menu>
<el-main class="detailed-content">
	<router-view />
</el-main>

javascript

/report是导航栏所在的页面,即report.vue,因为想让导航栏点击后还在本页面中,加了一个report作前缀防止跳转。

<script>

  export default {

    data() {
    return {
        navList:[
             {name:'/report/companyBackground', navItem:'公司背景'},
             {name:'/report/companyRisk',navItem:'司法风险'},
             {name:'/report/companyManager',navItem:'经营风险'},
        ]
                      
    }
  },
  methods: {
    handleSelect(key, keyPath) {
        console.log(key, keyPath);
    
      }
  }
}
</script>

路由

redirect为report打开后默认显示的页面

{
    name: 'report',
    path: '/report',
    component: report,
    redirect: '/report/companyBackground',
    children:  [
      {
        name: 'companyBackground',
        path: '/report/companyBackground',
        component: companyBackground
      },
      {
        name: 'companyRisk',
        path: '/report/companyRisk',
        component: companyRisk
      },
      {
        name: 'companyManager',
        path: '/report/companyManager',
        component: companyManager
      }
    ]
  }
  • 13
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

legendaryhaha

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值