美文网首页
导航和走马灯关联动态切换,element-ui组件的setAct

导航和走马灯关联动态切换,element-ui组件的setAct

作者: 空我我 | 来源:发表于2022-06-21 15:21 被阅读0次
    微信截图_20220621152014.png
    <template>
      <div class="page-container">
        <div class="flex nav-box">
          <span
            class="nav-box-item"
            :class="tabIndex === index ? 'active' : ''"
            @click="changeTab(index)"
            v-for="(item, index) in tabList"
            :key="index"
            >{{ item }}</span
          >
        </div>
        <el-carousel
          height="900px"
          direction="vertical"
          ref="carousel"
          @setActiveItem="setActiveItem"
          :autoplay="false"
          @change="changeItem"
        >
          <el-carousel-item v-for="item in 5" :key="item">
            <h3 class="medium">{{ item }}</h3>
          </el-carousel-item>
        </el-carousel>
      </div>
    </template>
    
    <script>
    // import { mapGetters } from "vuex";
    export default {
      name: "index",
      components: {},
      data() {
        return {
          tabList: ["网站首页", "测试一", "测试二", "测试三", "测试四"],
          tabIndex: 0,
        };
      },
      computed: {},
      methods: {
        changeItem(e) {
          this.tabIndex = e;
        },
        changeTab(index) {
          if (this.tabIndex === index) {
            return;
          }
          this.tabIndex = index;
          this.setActiveItem(index);
        },
        setActiveItem(index) {
          this.$refs.carousel.setActiveItem(index);
        },
      },
    };
    </script>
    
    <style lang="scss" scoped>
    .page-container {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
      overflow: hidden;
    }
    .nav-box {
      width: 100%;
      line-height: 3em;
      border-bottom: 1px solid #0955ab;
    }
    .nav-box-item {
      padding: 0 0.25rem /* 20/80 */;
      transition: all 0.6s linear;
      cursor: pointer;
    }
    .active {
      background: #0955ab;
      color: #fff;
    }
    .el-carousel__item h3 {
      color: #475669;
      font-size: 14px;
      opacity: 0.75;
      line-height: 200px;
      margin: 0;
    }
    
    .el-carousel__item:nth-child(2n) {
      background-color: #99a9bf;
    }
    
    .el-carousel__item:nth-child(2n + 1) {
      background-color: #d3dce6;
    }
    </style>
    
     
    

    相关文章

      网友评论

          本文标题:导航和走马灯关联动态切换,element-ui组件的setAct

          本文链接:https://www.haomeiwen.com/subject/jbkevrtx.html