導(dǎo)航和走馬燈關(guān)聯(lián)動態(tài)切換,element-ui組件的setActiveItem手動切換

微信截圖_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: ["網(wǎng)站首頁", "測試一", "測試二", "測試三", "測試四"],
      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>

 
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容