// 创建一个空数组来存储日期 var daysInMonth = []; // 获取当前日期对象 var currentDate = new Date(); // 获取当前月份 var currentMonth = currentDate.getMonth(); // 设置日期对象为当前月的第一天 currentDate.setDate(1); // 循环增加日期直到月份变化,记录每一天 while (currentDate.getMonth() === currentMonth) { var day = currentDate.getDate(); daysInMonth.push(day); currentDate.setDate(currentDate.getDate() + 1); } console.log(daysInMonth, '天数'); daysInMonth.forEach((item, index) => { var obj = { label: item + '号', value: item } this.dateList.push(obj); });