data(){
return{
time: new Date(),
timeData: '',//转成中文
}
}
created(){
this.before(0);;
},
/* 上一天 */
leftClick(){
this.before(1);
},
/* 下一天 */
rightClick(){
this.before(2);
},
/*
*上一天
*下一天
*/
before(state) {
var oldDateObj;
var newDateObj;
if(state==0){
oldDateObj = new Date((new Date()))
}else{
oldDateObj = new Date((this.time))
}
if(state===0){
newDateObj = new Date(oldDateObj.getTime());
}else if(state===1){
newDateObj = new Date(oldDateObj.getTime() - 86400000);
}else{
newDateObj = new Date(oldDateObj.getTime() + 86400000);
}
let year = newDateObj.getFullYear();
let month = newDateObj.getMonth() + 1;
let day = newDateObj.getDate();
month = month > 9 ? month : '0' + month;
day = day > 9 ? day : '0' + day;
this.time = `${year}-${month}-${day}`;
this.timeData = `${month}月${day}日`;
},