您可以使用以下代码来提取年月和计算该月份的最后一天:

// 提取年月
var yearMonth = this.reportingPeriodDate.substring(0, 7);

// 计算该月份的最后一天
var lastDay = new Date(yearMonth + '-01');
lastDay.setMonth(lastDay.getMonth() + 1);
lastDay.setDate(lastDay.getDate() - 1);

// 格式化最后一天
var formattedLastDay = lastDay.toISOString().substring(0, 10);

// 赋值完整代码
this.form.incomePeriodDateStart = yearMonth + '-01';
this.form.incomePeriodDateEnd = formattedLastDay;

以上代码将提取this.reportingPeriodDate的年月,并将this.form.incomePeriodDateStart赋值为该年月的第一天(即年月-01),将this.form.incomePeriodDateEnd赋值为该年月的最后一天。


原文地址: https://www.cveoy.top/t/topic/pmvH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录