獲取本週的開始日期和結束日期(本週週一到週日):
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 } },