<template>
<div class="container">
<el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="150px">
<el-form-item label="礼包名称" prop="name">
<el-input v-model.trim="ruleForm.name"></el-input>
</el-form-item>
<el-form-item label="礼包金额(元)" prop="money">
<el-input-number
v-model="ruleForm.money"
:min="1"
controls-position="right"
style="width: 200px"
></el-input-number>
</el-form-item>
<el-form-item label="倒计时时间" prop="countDown">
<el-input-number
v-model="ruleForm.countDown"
:min="1"
controls-position="right"
style="width: 200px"
></el-input-number>
</el-form-item>
<el-form-item :rules="[
{ minTime: ruleForm.available_after, validator: validateRate, trigger: 'blur' },
{required: true, message: '上线时间', trigger: 'blur'},
]" label="上线时间" prop="available_after">
<el-date-picker
v-model="ruleForm.available_after"
format="yyyy-MM-dd HH:mm"
placeholder="选择上线时间"
size="small"
type="datetime"
value-format="timestamp"
></el-date-picker>
</el-form-item>
<el-form-item :rules="[
{ maxTime: ruleForm.available_before, validator: validateRate, trigger: 'blur' },
{required: true, message: '下线时间', trigger: 'blur'},
]" label="下线时间" prop="available_before">
<el-date-picker
v-model="ruleForm.available_before"
format="yyyy-MM-dd HH:mm"
placeholder="选择下线时间"
size="small"
type="datetime"
value-format="timestamp"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">确认</el-button>
</el-form-item>
</el-form>
</div>
</template> <script>
export default {
data() {
return {
ruleForm: {
name: '',
money: '',
countDown: 1,
available_after: '',
available_before: ''
},
rules: {
name: [
{required: true, message: '请输入礼包名称', trigger: 'blur'},
],
money: [
{required: true, message: '请输入礼包金额', trigger: 'blur'},
],
countDown: [
{required: true, message: '请输入倒计时时间', trigger: 'blur'},
]
}
}
},
mounted() { },
methods: {
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});
},
validateRate(rule, value, callback) {
console.log(this.$refs.ruleForm.fields)
// this.$refs.ruleForm.fields[0].validateMessage ='error'
console.log(this.ruleForm.available_before <= this.ruleForm.available_after)
if (this.ruleForm.available_before === '' && this.ruleForm.available_after === '') {
callback(new Error('请选择时间'))
} else if (this.ruleForm.available_before == '' && this.ruleForm.available_after || this.ruleForm.available_after == '' && this.ruleForm.available_before) {
callback()
} else if (this.ruleForm.available_before <= this.ruleForm.available_after) {
callback(new Error('最小功率不能大于最大功率'))
} else {
if(this.$refs.ruleForm.fields[3].validateMessage){
this.$refs.ruleForm.fields[3].clearValidate();
}
if(this.$refs.ruleForm.fields[4].validateMessage){
this.$refs.ruleForm.fields[4].clearValidate();
}
callback();
}
}
},
computed: {}
}
</script>

主动触发错误提示操作

this.$refs.ruleForm.fields[4].validateMessage='';
//移除该表单项的校验结果
this.$refs.ruleForm.fields[4].clearValidate();

elmentui 表单验证问题的更多相关文章

  1. elment-ui表单验证

    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-widt ...

  2. jQuery学习之路(8)- 表单验证插件-Validation

    ▓▓▓▓▓▓ 大致介绍 jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的验证方法,包括 ...

  3. 玩转spring boot——AOP与表单验证

    AOP在大多数的情况下的应用场景是:日志和验证.至于AOP的理论知识我就不做赘述.而AOP的通知类型有好几种,今天的例子我只选一个有代表意义的“环绕通知”来演示. 一.AOP入门 修改“pom.xml ...

  4. form表单验证-Javascript

    Form表单验证: js基础考试内容,form表单验证,正则表达式,blur事件,自动获取数组,以及css布局样式,动态清除等.完整代码如下: <!DOCTYPE html PUBLIC &qu ...

  5. ASP.NET MVC5+EF6+EasyUI 后台管理系统(33)-MVC 表单验证

    系列目录 注:本节阅读需要有MVC 自定义验证的基础,否则比较吃力 一直以来表单的验证都是不可或缺的,微软的东西还是做得比较人性化的,从webform到MVC,都做到了双向验证 单单的用js实现的前端 ...

  6. 实现跨浏览器html5表单验证

    div:nth-of-type(odd){ float: left; clear: left; } .origin-effect > div:nth-of-type(even){ float: ...

  7. jQuery Validate 表单验证 — 用户注册简单应用

    相信很多coder在表单验证这块都是自己写验证规则的,今天我们用jQuery Validate这款前端验证利器来写一个简单的应用. 可以先把我写的这个小demo运行试下,先睹为快.猛戳链接--> ...

  8. jquery validate表单验证插件-推荐

    1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家.     1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素  3.鼠标离开后的正确.错误提示及鼠标移入时的帮 ...

  9. 表单验证插件之jquery.validate.js

    提到表单验证的插件,第一个想到的就是jquery.validate.js,所以小生想在这里稍微详细地说一下这款插件的具体使用方法,便于理解,我直接附上整段demo的代码(没怎么调样式,主要是看js): ...

  10. 走进AngularJs 表单及表单验证

    年底了越来越懒散,AngularJs的学习落了一段时间,博客最近也没更新.惭愧~前段时间有试了一下用yeoman构建Angular项目,感觉学的差不多了想做个项目练练手,谁知遇到了一系列问题.yeom ...

随机推荐

  1. redis cluster 部署

    redis cluster 部署 服务器说明 192.168.2.200:7000 ... 192.168.2.200:7005 创建集群目录 mkdir cluster-test cd cluste ...

  2. element table 表格嵌套

    ///////////////////////////  代码如下 <template> <div class="report-forms-page"> & ...

  3. Mybatisplus-Generator代码生成器-简单示例

    简单示例 import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotatio ...

  4. 函数记录CAM

    UF_PARAM_generate 生成刀轨 UF_PARAM_duplicate  此函数创建与"old_obj_tag"类型相同的新对象.它使用'old_obj_tag'数据初 ...

  5. lowcodeEngine设计器源码简析(创建流程,主要对象), 怎么生成一个左侧面板

    lowcodeEngine 怎么生成一个左侧面板 初始化流程 如何生成一个左侧面板 初始化插件时往skeleton.leftArea新增按钮,新增按钮时往skeleton.leftFloatArea新 ...

  6. didi-笔试

    import java.util.*; /** * 正整数,没有前导0 * 相邻的数字不能相同 * 可以被3整除 * 输入:?12?0?9?? * 输出:212101902 */ public cla ...

  7. 25 String 对象中的属性

    <!DOCTYPE html> <html lang="en">   <head>     <meta charset="UTF ...

  8. vue整体回顾

    vue大回顾 1 前端发展史 react vue---> 前端工程化---> 前后端分离 大前端:flutter uni-app 2 Vue介绍 单页面应用(spa) 组件化开发 mvvm ...

  9. docker+gunicorn+fastapi部署

    一.准备工作 1.先确保项目可以正常运行 2.使用pip freeze导出第三方库 3.在项目根目录新建pip.conf文件,写入一下内容 [global] index-url=http://pypi ...

  10. jekins 入门

    环境安装 gitlab 安装 使用 docker 安装 gitlab docker run -d --name gitlab --restart always --hostname gitlab.zd ...