导航和走马灯关联动态切换,element-ui组件的setAct
2022-06-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>