element-ui 表单自定义日期输入校验


methods: {
  validateDate(rule, value, callback){
     if (value) {       
       let timestamp = new Date(value).getTime()
       let start  = new Date(this.shiftStartTime).getTime()
       let end = new Date(this.shiftEndTime).getTime()
       if (end < timestamp || timestamp < start) {
         callback(new Error(`请在值班时间内选择  ${this.shiftStartTime} 至 ${this.shiftEndTime}`))
       } else {
         callback()
       }
     } else {
       callback()
     }
   }
}
<el-form-item
          label="记录时间"
          prop="recordDateTime"
          :rules="[
            { required: true, message: '记录时间不能为空', trigger: 'blur'},
            { validator: validateDate, trigger: ['blur', 'change'] }
          ]"
        >
          <el-date-picker
            v-model="summaryForm.recordDateTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期"
          ></el-date-picker>
        </el-form-item>

 

posted @ 2019-09-10 14:14  青春无敌小宇宙  阅读(5645)  评论(0编辑  收藏  举报