html
<el-button @click="searchStatisticsInfo(item)" :class="item.isChoose == true ? 'active' : ''" size="small" v-for="(item,index) in menulist" :key="index">{{item.name}}</el-button>
data
menulist: [{
id: 1,
isChoose: true,
name: '今天'
}, {
id: 2,
isChoose: false,
name: '近七天'
}, {
id: 3,
isChoose: false,
name: '近30天'
}, {
id: 4,
isChoose: false,
name: '近90天'
}],
JS
methods: {
searchStatisticsInfo (item) {
for (let item of this.menulist) {
item.isChoose = false;
}
item.isChoose = !item.isChoose;
}
}
如果数组中不包含isChoose 则需要改成$set的方式。
searchStatisticsInfo (item) {
for (let row of this.menulist) {
this.$set(row, "isChoose", false);
}
this.$set(item, "isChoose", true);
},