0
点赞
收藏
分享

微信扫一扫

vue 左滑右滑实现年份月份切换

君心浅语 2022-03-25 阅读 48
前端

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;
      }
    }

在这里插入图片描述

举报

相关推荐

0 条评论