首先第一步获取到当月的月份
let month = new Date().getMonth() + 1
循环当前月份前几个月,所以需要减1,直接push到数组中就可以了
const getRecentMonth = (month: any) => {
let arr = []
for (let i = month-1; i > 0; i--) {
let sixMonth = month - i
if (sixMonth <= 0) {
sixMonth = 12 + sixMonth
}
arr.push({name: sixMonth + '月', id: sixMonth})
}
arr.push({name: month + '月', id: month})
return arr;
}