vue moment 生成一个7x6=42格子的日历数据
calc(val = new Date()) { const m = moment(val).startOf('month'); const format = 'yyyy-MM-DD'; // 获取1号是星期几, 星期日的值为7 const wd = m.weekday() > 0 ? m.weekday() : 7; // 计算距离星期一差几天 const dd = Math.abs(wd - 1); // 获取开始时间 const startDate = m.clone().subtract(dd, 'day'); // 获取7x6=42个日期 const dates = new Array(42).fill(0).map((_, index) => { const date = startDate.clone().add(index, 'day'); return {date, format: date.format(format), nowMonth: index >= dd && index < (m.daysInMonth() + dd)} }); this.$set(this, 'dates', dates); // this.dates.splice(0, this.dates.length, dates); console.log(this.dates); }