//开始日期至结束日期
<el-form-item label="生效时间:" >
<el-date-picker
v-model="value2"
type="datetimerange"
value-format="yyyy-MM-dd HH:mm:ss"
:picker-options="pickerOptions"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="defaultTime"
align="right">
</el-date-picker>
</el-form-item>
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();
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]);
}
}]
},
computed: {
defaultTime() {
var date = new Date();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
let time=[];
time.push(`${hour}:${minute}:${second}`)
time.push(`${hour}:${minute}:${second}`)
return time;
}
},
//日期
<el-form-item label="开始日期">
<el-date-picker
v-model="formInline.startDate"
value-format="yyyy-MM-dd HH:mm:ss"
type="datetime"
:default-time="defaultTime"
placeholder="选择日期">
</el-date-picker>
</el-form-item>
computed: {
defaultTime() {
var date = new Date();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
return hour + ':' + minute + ':' + second;
}
},