vue element form动态prop校验问题
根据条件动态添加校验的问题动态切换prop值时不能默认为空,不然校验会失效,可以用'empty'代替空值<el-form label-width="95px" :model="form" ref="form" :rules="rules"><el-form-item label="总计星钻:":prop="form.auditType===1?'score':'empty'"&g
·
根据条件动态添加校验的问题
动态切换prop值时不能默认为空,不然校验会失效,可以用'empty'代替空值
<el-form label-width="95px" :model="form" ref="form" :rules="rules">
<el-form-item label="总计星钻:" :prop="form.auditType===1?'score':'empty'">
<el-input
class="input"
placeholder="请输入星钻"
v-model.number="form.score"
>
<template slot="append">个</template>
</el-input>
</el-form-item>
<el-form-item label="审核状态:" prop="auditType">
<el-radio-group v-model="form.auditType" @change="change">
<el-radio :label="1">通过</el-radio>
<el-radio :label="2">不通过</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<script>
export default {
data() {
return {
form: {
score: ''
}
rules: {
score: [{ required: true, message: "请输星钻", trigger: "blur" }],
}
}
},
methods: {
change(v) {
if(v===2){
this.$refs.form.clearValidate()
}
},
}
}
</script>
更多推荐
已为社区贡献36条内容
所有评论(0)