使用element-ui中的轮播图来简易实现标签页

<template>
  <div id="app">
    <div class="top">
      <ul>
        <li v-for="item in list" :key="item.id" :class="[flowAct === item.name ? 'active' : '']" @click="change(item.name)">{{item.name}}</li>
      </ul>
    </div>
    <el-carousel
      ref="changeCarousel"
      class="carousel"
      height="500px"
      indicator-position="none"
      arrow="never"
      :autoplay="false"
    >
      <el-carousel-item v-for="item in content" :key="item.id" :name="item.id.toString()">{{item.text}}</el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      flowAct: "1",
      list:[
        {id:1,name:'1'},
        {id:2,name:'2'},
        {id:3,name:'3'}
      ],
      content:[
        {id:1,text:'111111111111'},
        {id:2,text:'222222222222'},
        {id:3,text:'333333333333'}
      ]
    };
  },
  methods: {
    change(tab) {
      if (this.flowAct === tab) return;
      this.flowAct = tab;
      this.$refs.changeCarousel.setActiveItem(tab);
    },
  },
};
</script>

<style lang="scss" scoped>
#app {
  margin: 0;
  padding: 0;
}
.top {
  width: 600px;
  height: 50px;
  position: relative;
  left: 50%;
  margin-left: -300px;
  top: 5%;
  ul {
    display: flex;
    align-items: center;
    li {
      width: 200px;
      height: 50px;
      background-color: rgb(190, 190, 190);
      list-style-type: none;
      text-align: center;
      line-height: 50px;
      cursor: pointer;
      &:hover {
        background-color: rgb(190, 190, 190, 0.5);
      }
    }
  }
}
.active {
  border-top: cadetblue solid 5px;
  background-color: white !important;
}
.carousel {
  margin-top: 20px;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}
.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}
.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>

主要使用了setActiveItem()的方法,在点击切换时有了动画效果,效果如下
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值