Element UI Tabs 组件分页标签选中样式修改教程
<template>
<el-tabs v-model="carouselTypeSelected" :stretch="false" @tab-change="handleClick">
<el-tab-pane v-for="(item, index) in carouselType" :label="item.dictLabel" :name="index" :key="item.dictLabel">
<template #label>
<div class="cat-tab" :class="{ active: carouselTypeSelected === index }">
<span>{{ item.dictLabel }}</span>
</div>
</template>
</el-tab-pane>
</el-tabs>
</template>
<script>
export default {
data() {
return {
carouselTypeSelected: '', // 初始化选中的分页标签
carouselType: [ /* 分页标签数据 */ ],
};
},
methods: {
handleClick(tab) {
this.carouselTypeSelected = tab.name; // 点击分页标签时改变样式
},
},
};
</script>
<style scoped>
.cat-tab {
min-width: 100px;
font-size: 14px;
font-weight: bold;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.cat-tab.active {
color: blue; // 设置选中的标签字体颜色为蓝色
}
</style>
<p>在上述代码中,我们通过给选中的分页标签添加 'active' 类来改变字体颜色。同时在 'handleClick' 方法中将选中的分页标签的索引赋值给 'carouselTypeSelected',从而触发样式的改变。</p>
原文地址: https://www.cveoy.top/t/topic/pajf 著作权归作者所有。请勿转载和采集!