默认在时间选择器里面
![]()
js文件
// 时间格式化
// Format 在组件created里引用
Date.prototype.Format = function (fmt) { // author: meizz
var o = {
"M+": this.getMonth() + 1, // 月份
"d+": this.getDate(), // 日
"h+": this.getHours(), // 小时
"m+": this.getMinutes(), // 分
"s+": this.getSeconds(), // 秒
"q+": Math.floor((this.getMonth() + 3) / 3), // 季度
"S": this.getMilliseconds() // 毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
组件
<el-form :inline="true" :model="filters">
<el-form-item label="发起时间:" prop="dateranTime">
<el-date-picker
v-model="filters.effectiveTime"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="['00:00:00', '23:59:59']"
value-format="yyyy-MM-dd HH:mm:ss"
></el-date-picker>
</el-form-item>
</el-form>
// 别忘了引入js文件哦~
created(){
// this.filters.effectiveTime 是上面 v-model绑定的
this.filters.effectiveTime = [
new Date().Format("yyyy-MM-dd") + " 00:00:00",
new Date().Format("yyyy-MM-dd") + " 23:59:59",
];
// Format是js文件里的
}