The date starts from Sunday, and it is found out that the first day of the week is different in various countries, so this is the case. Add: picker-options="{'firstDayOfWeek': 1}" attribute to the control to control, the optional range is 1-7
<el-form-item label="周期:" prop="misCycle">
<el-date-picker
v-model="temp1.misCycle"
:picker-options="{'firstDayOfWeek': 1}"
type="week"
format="yyyy 第 WW 周"
placeholder="请选择周期"
style="width:100%"
@change="setWeekNum"
/>
</el-form-item>
data() {
return {
temp1: {
// 周期
misCycle: '',
},
// 周期开始时间
startDate: '',
// 周期结束时间
endDate: '',
// 周期时间
finalDate: ''
}
},
methods: {
p(s) {
return s < 10 ? '0' + s : s
},
// 时间
setWeekNum() {
console.log(this.temp1.misCycle)
const newTime = this.temp1.misCycle.getTime()
const day = this.temp1.misCycle.getDay()
const oneDayTime = 24 * 60 * 60 * 1000
const fromTime = newTime - day * oneDayTime
const endTime = newTime + (7 - day) * oneDayTime
const fromDate = new Date(fromTime)
this.startDate = fromDate.getFullYear() + '\xa0' + this.p((fromDate.getMonth() + 1)) + '\xa0' + this.p(fromDate.getDate() + 1)
const toDate = new Date(endTime)
this.endDate = toDate.getFullYear() + '\xa0' + this.p((toDate.getMonth() + 1)) + '\xa0' + this.p(toDate.getDate())
console.log(this.startDate)
console.log(this.endDate)
this.finalDate = this.startDate + '-' + this.endDate
console.log(this.finalDate)
}
}