1、获取上个月第一天和最后一天
let nowDays = new Date()
let year = nowDays.getFullYear()
let month = nowDays.getMonth()
if (month == 0) {
month = 12
year = year - 1
}
if (month < 10) {
month = '0' + month
}
let lastDate = new Date(year, month, 0)
let startDate = new Date(year + '-' + month + '-01') //上个月第一天
let endDate = new Date(year + '-' + month + '-' + lastDate.getDate()) //上个月最后一天
2、获取当前月前N个月份
getMonthList (number) {
let dateList = []
let date = new Date()
let Y = date.getFullYear()
let M = date.getMonth()
for (let i = 0; i < number; i++) {
let dateOption = ''
if (M - 1 >= 0) {
} else {
M = 12
Y = Y - 1
}
let m = M
m = m < 10 ? '0' + m : m
dateOption = Y + '-' + m
M--
dateList.push(dateOption)
}
return dateList
}