npm i dayjs --save
import dayjs from 'dayjs';
/**
* 获取日期的函数
*/
updateWeek(weekOffset) {
const today = dayjs()
const timestamp = Math.round(new Date())
const date = new Date(timestamp)
const weekday = date.getDay()
const targetWeek = weekday === 0 ? weekOffset - 1 : weekOffset
this.beginDate = today.add(targetWeek, 'week').startOf('week').add(1, 'day').format('YYYY-MM-DD')
this.endDate = today.add(targetWeek, 'week').endOf('week').add(1, 'day').format('YYYY-MM-DD')
}
/**
* 获取本周
*/
this.updateWeek(0)
/**
* 获取上周
*/
this.updateWeek(-1)
/**
* 获取下周
*/
this.updateWeek(1)
标签:week,const,dayjs,获取,一周,updateWeek,add,周日
From: https://www.cnblogs.com/mengqc1995/p/18426785