Files
yudao-dev/src/views/home/costComponents/changeBase.vue
‘937886381’ 80deffbb42 新增页面
2025-12-25 16:48:17 +08:00

72 lines
1.7 KiB
Vue

<template>
<div class="changeBase">
<div class="base-item" :class="{ isChecked: activeButton === index, noChecked: activeButton !== index }"
@click="handleClick(index)"
v-for="(item, index) in buttonList"
:key="index"
>
{{ item }}
</div>
</div>
</template>
<script>
export default {
name: "Container",
data() {
return {
activeButton: 0, // 默认选中“总览”
buttonList: ['总览', '宜兴', '漳州', '自贡', '桐城', '洛阳', '合肥']
};
},
methods: {
handleClick(index) {
this.activeButton = index; // 更新选中状态
// 触发自定义事件,将当前选中的值(如“总览”“宜兴”)传递给父组件
this.$emit('selectChange', index+1);
}
},
// 初始化时就将默认选中的值传递给父组件
mounted() {
this.$emit('selectChange', this.activeButton +1);
}
};
</script>
<style scoped lang="scss">
/* 样式不变,省略 */
.changeBase {
display: flex;
width: fit-content; // 宽度由子项总宽度决定
// justify-content: space-around;
// gap: 50px;
// overflow-x: auto;
// padding: 10px 0;
.base-item {
width: 264px;
height: 82px;
font-family: YouSheBiaoTiHei;
font-size: 38px;
line-height: 54px;
text-align: center;
font-style: normal;
cursor: pointer;
white-space: nowrap;
margin-right: -35px;
}
// .isChecked {
// color: #F9FBFE;
// background: url(../../../assets//img/baseChecked.png) no-repeat;
// background-size: cover;
// }
// .noChecked {
// color: rgba(30, 22, 81, 1);
// background: url(../../../assets//img/baseNoChecked.png) no-repeat;
// background-size: cover;
// }
}
</style>