1.定义数据
selectYear: day().year(),
selectMonth: day().month() + 1,
2.结构
<div class="date_picker">
<van-button @click="pre()">
<van-icon name="arrow-left" />
</van-button>
<span>{{ `${selectYear}年${selectMonth}月` }}</span>
<van-button @click="next()">
<van-icon name="arrow" />
</van-button>
</div>
3.方法
import day from "dayjs";
next() {
this.selectMonth = this.selectMonth + 1;
if (this.selectMonth > 12) {
this.selectMonth = 1;
this.selectYear = this.selectYear + 1;
}
},
pre() {
this.selectMonth = this.selectMonth - 1;
if (this.selectMonth < 1) {
this.selectMonth = 12;
this.selectYear = this.selectYear - 1;
}
}
