获取本周的开始日期和结束日期(本周周一到周日):
var currentTime = new Date()
this.getThisWeekData(currentTime, 0)
点击切换上周的周历(把当前周的周一的时间传进去就行,如“2024-08-05”):
this.getThisWeekData(currentData.startData, -7)
点击切换下周的周历(把当前周的周一的时间传进去就行,如“2024-08-05”):
this.getThisWeekData(currentData.startData, 7)
getThisWeekData(time, OptType) {//optType 0:本周 -7:上周 7:下周var date = new Date(time)if (OptType === 0) {var tempStartData = date.setDate(date.getDate() - date.getDay() + 1)var startData = this.getTimeStyle(tempStartData)console.log('本周一', startData)} else if (OptType === -7){var tempStartData = date.setDate(date.getDate() - date.getDay() -6)var startData = this.getTimeStyle(tempStartData)console.log('上周一', startData)}else if (OptType === 7) {var tempStartData = date.setDate(date.getDate() - date.getDay() +8)var startData = this.getTimeStyle(tempStartData)console.log('下周一', startData)} var tempEndData = date.setDate(date.getDate() + 6)var endData = this.getTimeStyle(tempEndData)console.log('周日', endData)this.currentData = {startData: startData,endData: endData}},