js 写点击上一月 下一月时候切换

<el-col :span="5"v-show="listVisible" style="margin-left: 50px">
                <el-button type="primary" size="mini"  @click="onday">上一月</el-button>
                <el-button type="primary" size="mini" @click="nextday">下一月</el-button>
 </el-col>

 

 点击上一月,下一月进行切换 

 

//搜索上一月数据
onday(){
let date = new Date(this.searchVal.dt); //获取日期 日期是2020-07 写成你自己的
let CurrentDate = "";
let year = date.getFullYear();
let month = (date.getMonth()) < 10 ? "0" +(date.getMonth()) : (date.getMonth()); //自动补0
console.log(year);
console.log(month);
if(month<1){
CurrentDate = (year - 1) + "-" + "12"
}else{
CurrentDate = year + "-" + month
}
this.searchVal.dt=CurrentDate;
this.handleSearch();
},
//搜索下一月数据
nextday(){
let date = new Date(this.searchVal.dt);
let CurrentDate = "";
let year = date.getFullYear();
let month = (date.getMonth() + 1 + 1) < 10 ? "0" +(date.getMonth() + 1 + 1) : (date.getMonth() + 1 + 1);
if(month>12){
CurrentDate = (year + 1) + "-" + "01"
}else{
CurrentDate = year + "-" + month
}
this.searchVal.dt=CurrentDate;
this.handleSearch();
},
欢迎指点和评论;
posted @ 2020-07-23 14:30  丿狂奔的蜗牛  阅读(776)  评论(0编辑  收藏  举报