const today = new Date(); const dateArray = []; const dayOfWeekArray = []; const yearMonthDayArray = []; for (let i = 0; i < 7; i++) { // 获取时间戳 const d = new Date(today); console.log(d); console.log(today); console.log(today.getDate()); console.log(d.setDate(today.getDate())); d.setDate(today.getDate() + i); console.log(d); console.log(d.getDate()); // 数字 dateArray.push(d.getDate()); console.log(dateArray); const dayOfWeekStr = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][d.getDay()]; // 星期几 console.log(dayOfWeekStr); console.log(d); console.log(d.getDay()); dayOfWeekArray.push(dayOfWeekStr); console.log(dayOfWeekArray); const yearMonthDayStr = `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`; // 获取到几年几月几日 yearMonthDayArray.push(yearMonthDayStr); console.log(yearMonthDayArray); console.log(d.getMonth() + 1); console.log(d.getMonth()); } var num = []; for (let i = 0; i < dateArray.length; i++) { if (dayOfWeekArray[i] == '周一') { num.push({ data: dateArray[i], numa: dayOfWeekArray[i], time: yearMonthDayArray[i], time_data: res.data.list.mon, color: 'background-color: #EFEFEF;color:black;' }) } else if (dayOfWeekArray[i] == '周二') { num.push({ data: dateArray[i], numa: dayOfWeekArray[i], time: yearMonthDayArray[i], time_data: res.data.list.tue, color: 'background-color: #EFEFEF;color:black;' }) } else if (dayOfWeekArray[i] == '周三') { num.push({ data: dateArray[i], numa: dayOfWeekArray[i], time: yearMonthDayArray[i], time_data: res.data.list.wed, color: 'background-color: #EFEFEF;color:black;' }) } else if (dayOfWeekArray[i] == '周四') { num.push({ data: dateArray[i], numa: dayOfWeekArray[i], time: yearMonthDayArray[i], time_data: res.data.list.thu, color: 'background-color: #EFEFEF;color:black;' }) } else if (dayOfWeekArray[i] == '周五') { num.push({ data: dateArray[i], numa: dayOfWeekArray[i], time: yearMonthDayArray[i], time_data: res.data.list.fri, color: 'background-color: #EFEFEF;color:black;' }) } else if (dayOfWeekArray[i] == '周六') { num.push({ data: dateArray[i], numa: dayOfWeekArray[i], time: yearMonthDayArray[i], time_data: res.data.list.sat, color: 'background-color: #EFEFEF;color:black;' }) } else if (dayOfWeekArray[i] == '周日') { num.push({ data: dateArray[i], numa: dayOfWeekArray[i], time: yearMonthDayArray[i], time_data: res.data.list.sun, color: 'background-color: #EFEFEF;color:black;' }) } } that.week_inner = num; console.log(that.week_inner); this.currentTime(); }