1.需要在以下方法中传入年月(2022-05)

2.代码如下,可供大家参考

getDate(val) {
			let date = new Date(val);
			let new_year = date.getFullYear(); // 取当前的年份
			let month = date.getMonth();
			let new_month = month + 1; // 取当前的月份
			let mon = "";
			let day = "";
			if (month > 12) {
				new_month -= 12; // 月份减
				new_year++; // 年份增
			}
			let firstDay = new Date(new_year, new_month, 1); // 取当年当月中的第一天
			let lastDay = new Date(
				firstDay.getTime() - 1000 * 60 * 60 * 24
			).getDate(); // 获取当月最后一天日期
			if (firstDay.getMonth() < 10) {
				mon = "0" + firstDay.getMonth();
			} else {
				mon = firstDay.getMonth();
			}
			if (lastDay < 10) {
				day = "0" + lastDay;
			} else {
				day = lastDay;
			}
			let startDate =
				firstDay.getFullYear() +
				"-" +
				mon +
				"-" +
				"0" +
				firstDay.getDate();
			let endDate = firstDay.getFullYear() + "-" + mon + "-" + day;
			this.dateRange = startDate + "~" + endDate;
		},

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐