<template>
<div>
<el-form ref="dataFrom" :model="dataFrom" :rules="rules">
<el-form-item label="用户名">
<el-input v-model="dataFrom.userName"></el-input>
</el-form-item>
</el-form>
<el-button @click="submitData()"> 提交</el-button>
</div>
</template>
<script>
export default {
name: "settlementSignReport",
data() {
return {
dataFrom: {
userName: ''
},
rules: {
userName: [
{required: true, message: '请输入用户名', trigger: 'blur'},
]
}
}
},
methods: {
submitData() {
this.$refs['dataFrom'].validateField('userName', valid => {
if (!valid) {
alert(123)
} else {
alert(321)
}
})
}
}
}
</script>
用form 表单验证 validate 的 validateField 去验证指定的
如果要验证整个表单:
this.$refs['dataFrom'].validate((valid)=>{
if(valid){
//验证通过
}
})