注意时间一定是Data型 的.
created(){
// 初始化默认时间
this.defaultDate()
}
methods(){
defaultDate(){
const end = new Date()
const start = new Date()
const dayOfThisMon = end.getDate(); // 获取当前日(1-31)
start.setTime(start.getTime() - (3600 * 1000 * 24 * (dayOfThisMon-1)))
this.daterangeBizOccurDate = [start, end] //将值设置给插件绑定的数据
}
}
<el-date-picker
v-model="daterangeBizOccurDate"
style="width: 240px"
value-format="yyyy-MM-dd HH:mm:ss"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="['00:00:00', '23:59:59']"
:picker-options="pickerOptions"
></el-date-picker>
data() {
return {
pickerOptions: {
shortcuts: [{
text: '最近一周',
onClick(picker) {
const end = new Date()
const start = new Date()
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
picker.$emit('pick', [start, end])
}
}, {
text: '本月',
onClick(picker) {
const end = new Date()
const start = new Date()
const dayOfThisMon = end.getDate(); // 获取当前日(1-31)
start.setTime(start.getTime() - (3600 * 1000 * 24 * (dayOfThisMon-1)))
picker.$emit('pick', [start, end])
}
}, {
text: '最近一个月',
onClick(picker) {
const end = new Date()
const start = new Date()
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
picker.$emit('pick', [start, end])
}
}, {
text: '最近三个月',
onClick(picker) {
const end = new Date()
const start = new Date()
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
picker.$emit('pick', [start, end])
}
}]
}}