<el-form-item label="生效時間" prop="startTime"> <el-date-picker v-model="formAdd.startTime" :disabled="isOperation == false ? formAdd.status != 1 : false" style="width: 100%" type="datetime" placeholder="請選擇生效時間" value-format="yyyy-MM-dd HH:mm:ss" @change="pickerOptionsStartChange" :picker-options="pickerOptionsStart" > </el-date-picker> </el-form-item> <el-form-item label="有效時間" prop="expireTime"> <el-date-picker v-model="formAdd.expireTime" :disabled="isOperation == false ? formAdd.status != 1 : false" style="width: 100%" type="datetime" placeholder="請選擇有效時間" value-format="yyyy-MM-dd HH:mm:ss" :picker-options="{ disabledDate(time) { let beginDateVal = formAdd.startTime; if (beginDateVal) { if ( new Date(beginDateVal).Format('yyyy-MM-dd') == new Date(formAdd.expireTime).Format('yyyy-MM-dd') ) { defaultTime = `${new Date(beginDateVal).Format( 'hh:mm:ss' )} - 23:59:59`; } else { defaultTime = '00:00:00 - 23:59:59'; } return time.getTime() < new Date(beginDateVal).getTime(); } }, selectableRange: defaultTime }" > </el-date-picker> </el-form-item>
<script> export default { data() { return { pickerOptionsStart: { disabledDate: time => { let endDateVal = this.formAdd.expireTime; if (endDateVal) { //console.log("开始时间", this.formAdd.startTime); return time.getTime() >= new Date(endDateVal).getTime(); } } }, defaultTime: "00:00:00 - 23:59:59", formAdd: { startTime: "", expireTime: "", } } } </script>
new Date(beginDateVal).Format('yyyy-MM-dd') 其中.Format('yyyy-MM-dd')是对new Date()的原生扩展,在上个文章有
评论区