vue表单校验
在提交的时候校验
1 this.$refs['ruleForm'].validate((valid) => { 2 if (valid) {}})
rules信息可以在行内写,也可以在data里面定义例如‘
rules: { qqq: [{ required: true, message: '请输入名称', trigger: 'change' }], www: [{ required: true, message: '请选择信息', trigger: 'change' }], eee: [{ required: true, message: '请选择', trigger: 'change' }],
行内
:rules="{ required: true, message: item.dName, trigger: 'blur' }"
动态绑定model值prop值label值
<el-form-item class="form-item" :label="item.formulaFieldName + ':'" :prop="item.formulaFieldCode" :rules="{ required: true, message: item.formulaFieldName, trigger: 'blur' }">
<el-date-picker v-model="model[item.formulaFieldCode]" type="year" placeholder="选择日期" value-format="yyyy" format="yyyy"> </el-date-picker>
</el-form-item>
关闭表单校验//最好在打开弹窗前就进行关闭校验
el-select切换值时如果要清空其他选项一定要用this.$set()这样来用,要不然会引起校验提示出错
重点!!!!!如果你清空了校验之后,必须把表单绑定的model附上默认值 不然input框会输入不了
this.$refs['ruleForm'].resetFields()
if (that.$refs['form'] !== undefined) {
this.$refs['form'].resetFields()
}
——————————————————————————————————————————————————————————————————————————————————————
清除当前ref所在行的校验 <el-form-item label='123213:' prop='dztzType' ref='formItemFormType'> this.$nextTick(()=>{ this.$refs.formItemFormType.clearValidate() })
本文来自博客园,作者:prince11,转载请注明原文链接:https://www.cnblogs.com/prince11/p/18331759