https://blog.csdn.net/weixin_41941325/article/details/80936603 (opens new window)
<van-button
v-for="(item,index) in showYearList"
:key="index"
>{{item}}
</van-button>
<van-button @click="changeFold('year')" size="small">{{yearFold?'更多':'收起'}}</van-button>
1
2
3
4
5
6
7
2
3
4
5
6
7
computed:{
showYearList: {
get() {
if (this.yearFold) {
if (this.yearList.length < 4) {
return this.yearList;
}
const newArr = [];
for (let i = 0; i < 4; i++) {
const item = this.yearList[i];
newArr.push(item);
}
return newArr;
}
return this.yearList;
},
set(val) {
this.showYearList = val;
},
}
}
changeFold(){
this.yearFold = !this.yearFold;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24