1.代码示例
<template>
<el-date-picker
suffix-icon="el-icon-date"
range-separator="-"
type="daterange"
placeholder="选择日期"
v-model="dateBucket"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"></el-date-picker>
</template>
<script>
export default {
name: "test",
data() {
return {
dateBucket: [this.dateFormat(new Date(Date.now() - 3600 * 1000 * 24 * 14), "yyyy-MM-dd"), this.dateFormat(new Date(),"yyyy-MM-dd")],
form:{
beginDate: '',
endDate: ''
}
}
},
methods: {
dateFormat(date, format) {
format = format || 'yyyy-MM-dd hh:mm:ss';
if (date !== 'Invalid Date') {
let o = {
"M+": date.getMonth() + 1, //month
"d+": date.getDate(), //day
"h+": date.getHours(), //hour
"m+": date.getMinutes(), //minute
"s+": date.getSeconds(), //second
"q+": Math.floor((date.getMonth() + 3) / 3), //quarter
"S": date.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
(date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (let k in o)
if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length === 1 ? o[k] :
("00" + o[k]).substr(("" + o[k]).length));
return format;
}
return '';
}
},
watch: {
'dateBucket'(){
if (this.dateBucket && this.dateBucket.length == 2) {
this.form.beginDate = this.dateBucket[0] + ' 00:00:00';
this.form.endDate = this.dateBucket[1] + ' 23:59:59';
}else{
this.form.beginDate = "";
this.form.endDate = "";
}
}
}
}
</script>
2.示例图片
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/92423.html