<el-form :model="ruleForm"
:rules="rules"
ref="ruleForm"
label-width="100px"
>
<el-form-item label="项目来源" prop="projectSource"
:rules="projectSourceIsMust?rules.projectSource:[
{required: false, message: '请输入项目来源', trigger: 'blur' },
{ max: 1000, message: '项目来源不能超过1000位', trigger: 'blur'}]">
<el-input type="textarea" :autosize="{ minRows: 3}" v-model="ruleForm.projectSource" ></el-input>
</el-form-item>
</el-form>
projectSourceIsMust为特殊条件,如果为true,则为必填校验规则,否则就是required: false
data中数据定义:
data () {
return {
ruleForm: {
projectSource:''
},
rules: {
projectSource: [
{required: true, message: '请输入项目来源', trigger: 'blur' },
{ max: 1000, message: '项目来源不能超过1000位', trigger: 'blur' },]
}
}
}