function mathDate(){
var nowDate = new Date()
let nowYear = nowDate.getFullYear();
let nowMonth = (nowDate.getMonth())<10?'0'+(nowDate.getMonth()):(nowDate.getMonth());
var d = new Date(nowYear+'-'+nowMonth);
var result = [];
d.setMonth(d.getMonth() + 2);
for(var i = 1; i < 13; i++) {
d.setMonth(d.getMonth() - 1);
let m = d.getMonth() + 1;
m = m < 10 ? ("0" + m) : m;
let val = {
value: d.getFullYear() + "年" + m + '月',
label:d.getFullYear() + "-" + m
}
//在这里可以自定义输出的日期格式
result.push(val);
}
// 一年的日期
// 当前年月
let thisMonth = (d.getMonth())<10?'0'+(d.getMonth()):(d.getMonth());
let thisYear = d.getFullYear()+1;
if(thisMonth == 0){
this.nowData = (thisYear-1)+"-12";
}else{
this.nowData = thisYear+"-"+thisMonth;
}
let nowobj ={
value:thisYear+'年'+thisMonth+'月',
label:thisYear+'-'+thisMonth
}
this.selectData = result;
this.selectValue = this.nowData
}
可以添加当前月份 把获取的数组处理一下
网友评论