Vue实现tab切换

Vue实现tab切换

一、实现效果图
在这里插入图片描述
备注:上标题控制下标题

二、实现思路
通过给上面的标题定义(@click)事件,点击获取下标的方式实现高亮

三、代码实现
在这里插入图片描述
data数据
在这里插入图片描述
methods事件
在这里插入图片描述
四、代码实现
html

 <!-- 总体态势 区域交通 微观交通 -->
    <div class="area-title">
      <ul>
        <li
          v-for="(item, index) in titleArr" :key="item.id"
          :class="activeIndex == index ? 'active' : ''"
          @click="changTitle(item,index)"
        >
          {{ item.name }}
        </li>
      </ul>
    </div>
    <div class="bottom-box">
      <div class="group-title">
        <ul>
          <li v-for="(item, index) in groupNewArr" :key="item.id" :class="activeBottomIndex == index ? 'active' : ''" @click="changeBottomTitle(index)">{{item.name}}</li>
        </ul>
      </div>
    </div>

export default

export default {
  //name:"Index",
  components: {
    LeftBox,
    RightBox,
  },
  data() {
    return {
      activeIndex: 0,
      activeBottomIndex: 0, //下面导航下标
      //顶部标题
      titleArr: [
        { name: "总体态势", id: 4 },
        { name: "区域交通", id: 1 },
        { name: "微观交通", id: 2 },
      ],
      // 底部标题
      groupArr: [
        {
          type: 4,
          groupTypeArr: [
            { name: "总体态势", id: 11 },
            { name: "人口分布", id: 12 },
            { name: "出行需求", id: 13 },
            { name: "城市结构", id: 14 },
          ],
        },
        { type: 1, 
          groupTypeArr: [{ name: "区域交通", id: 21 }] },
        {
          type: 2,
          groupTypeArr: [
            { name: "短途态势", id: 31 },
            { name: "人口分布", id: 32 },
            { name: "出行需求", id: 33 },
          ],
        },
      ],
      groupNewArr: [],
    };
  },
  methods: {
    // 点击顶部栏切换标题
    changTitle(item,index) {
      this.activeIndex = index;
     // console.log(item)
     //console.log(index) 0  1  2
     this.activeBottomIndex=0;
       this.groupArr.forEach((elem,index) => {
       //console.log(elem.type)  0  1  2
      //console.log(elem.groupTypeArr) 
      if(item.id == elem.type){
         this.groupNewArr = elem.groupTypeArr
         //console.log(this.groupNewArr)
      }
       });
    },
    changeBottomTitle(index){
      this.activeBottomIndex = index
    },
  },
  mounted(){
     this.groupNewArr=this.groupArr[0].groupTypeArr
  }
};
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值