Vue中的嵌套路由

//router中的js你可以这样写
// 定义一个数组
const routes = [
  {
    path: '/',
    redirect: "/home",
  },{
    path: '/home',
    name: 'home',
    component: Home,
    redirect: "/home/index",
    children:[{
      path: "index",
      name: 'home',
      component: () => import('../views/Home/children/Index.vue') //按需引入组件
    },{
      path: "showresult",
      name: 'home',
      component: () => import('../views/Home/children/Showresult.vue') //按需引入组件
    },{
      path: "infosharing",
      name: 'home',
      component: () => import('../views/Home/children/Infosharing.vue') //按需引入组件
    },{
      path: "openability",
      name: 'home',
      component: () => import('../views/Home/children/Openability.vue') //按需引入组件
    },{
      path: "dataapplication",
      name: 'home',
      component: () => import('../views/Home/children/Dataapplication.vue') //按需引入组件
    }]
  }]
//然后在header中你可以这样写
<div>
	<ul>
      <li>
          <router-link to="index">首页</router-link>
        </li>
        <li>
          <router-link to="showresult">成果展示</router-link>
        </li>
        <li>
          <router-link to="openability">能力开放</router-link>
        </li>
        <li>
          <router-link to="dataapplication">数据应用</router-link>
        </li>
        <li>
          <router-link to="infosharing">信息共享</router-link>
        </li>
      </ul>
	//记得加个站位符	
	<router-view></router-view>
</div>
//因为就是演示一下没有用v-for你可以用v-for循坏这样你可以冬天添加一个类名可以添加选择动态效果
//在说一下我加动态类名都是怎么加
<div class="section-1">
    <ul class="infoimg">
        <li :class='currentindex==index?"current":""' v-for="(item,index) in DataApply" :key='item.id'>
            <img :src="item.imgpath" alt="">
         </li>
	</ul>
    <ul class="title">
        <li @mouseover='change(index)' :class='currentIndex==index?"active":""' v-for="(item,index) in DataApply" 							:key='item.id'>
            <img :src="item.titleimg" alt="">
         </li>
    </ul>
</div>
//data中
// 当前按钮
currentIndex: null,
// 当前图片
currentindex: 0,
        
methods: {
  change(index){
      this.currentIndex = index;
      this.currentindex = index;
  }
},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值