css实现月份当月高亮,当月之后的置灰,当月之前的点击高亮
话不多说直接上代码:
<template>
<div class="month_box">
<div v-for="i in 12" :class="{'month_active':form.monthNum==''?form.month==i:form.monthNum == i && form.monthNum<=form.month,'month_active_next':form.month < i}" @click="clickMonth(i)"> {{ i + '月' }}</div>
</div>
</template>
<script>
export default {
form: {
month: new Date().getMonth() + 1 ,//月份
monthNum:"",
},
methods:{
clickMonth(index){//点击选择月份
if(index>new Date().getMonth()+1){
}else{
this.form.monthNum = index;
console.log(index)
}
},
}
}
</script>
<style lang="less">
.month_box{
width: 100%;
height: 100%;
display: inline-flex;
align-items: center;
div{
width:80px;
height: 100%;
border:1px solid lightgray;
display: inline-flex;
align-items: center;
justify-content: center;
margin-left: 1%;
border-radius: 6px;
}
.month_active{
background: #1E7AE1;
color: #FFFFFF;
}
.month_active_next{
background: lightgray;
}
}
</style>