html: <el-form-item label="周期:">
<el-date-picker v-model="value" type="week" @change="handleGetWeek" format="yyyy 第 WW 周" placeholder="选择周"></el-date-picker>
<span>( {{this.startDate}} 至 {{ this.endDate }} )</span>
</el-form-item>
mounted(){ this.value = new Date() } // 给定当前日期
methods:{
p (s) {
return s < 10 ? '0' + s : s
},
handleGetWeek () {
let newTime = this.value.getTime()
let day = this.value.getDay()
let oneDayTime = 24 * 60 * 60 * 1000
let fromTime = newTime - day * oneDayTime
let endTime = newTime + (6 - day) * oneDayTime
let fromDate = new Date(fromTime)
this.startDate = fromDate.getFullYear() + '-' + this.p((fromDate.getMonth() + 1)) + '-' + this.p(fromDate.getDate())
let toDate = new Date(endTime)
this.endDate = toDate.getFullYear() + '-' + this.p((toDate.getMonth() + 1)) + '-' + this.p(toDate.getDate())
},
}
网友评论