functiongetMonthArray(startDate, endDate) { let startYear = parseInt(startDate.split('-')[0]) let startMonth = parseInt(startDate.split('-')[1]) let yearDiff = parseInt(endDate.split('-')[0]) - startYear let monthDiff = parseInt(endDate.split('-')[1]) - startMonth let totalMonth = yearDiff * 12 + monthDiff let result = []
for (let i = 1; i < totalMonth; i++) { // 这里i = 1 是因为只计算到截止日期的前一个月 startMonth++ if (startMonth > 12) { startMonth = 1 startYear++ } let temp = String(startMonth).length < 2 ? `0${startMonth}` : startMonth result.push(`${startYear}-${temp}`)
functiongetMonthArray(startDate, endDate) { let startYear = parseInt(startDate.split('-')[0]) let startMonth = parseInt(startDate.split('-')[1]) let yearDiff = parseInt(endDate.split('-')[0]) - startYear let monthDiff = parseInt(endDate.split('-')[1]) - startMonth let totalMonth = yearDiff * 12 + monthDiff let result = []
for (let i = 0; i <= totalMonth; i++) { let temp = String(startMonth).length < 2 ? `0${startMonth}` : startMonth result.push(`${startYear}-${temp}`) startMonth++ if (startMonth > 12) { startMonth = 1 startYear++ }