Element el-form根据选择条件动态控制表单必填项
作者:互联网
业务场景:当select=A时 C非必填 反之当select=B时C必填
代码实现
<el-form-item label="支付方式 :" :rules="[{ required: true, message: '请选择支付方式', trigger: 'change' }]" prop="couponBatchPaytype">
<el-select @change="changeCouponBatchPaytype" clearable v-model="ruleForm.couponBatchPaytype" placeholder="请选择支付方式" style="width:30%">
<el-option label="明点转账" value="0"></el-option>
<el-option label="暗点抵扣" value="1"></el-option>
</el-select>
</el-form-item>
<el-form-item label="选择客户:" prop="custrelCode" :rules="ruleForm.couponBatchPaytype == 1 ? rules.custrelCode : [{ required: false }]">
<el-select @change="ysMakeActive" v-model="value2" value-key="userinfoCode" style="width:30%" placeholder="请选择客户" clearable>
<el-option v-for="item in userArr2" :key="item.userinfoCode" :label="item.userinfoCompname" :value="item"> </el-option>
</el-select>
</el-form-item>
data部分
rules: {
custrelCode: [{ required: true, message: '请选择客户', trigger: 'change' }],
},
标签:el,必填,动态控制,message,data,select 来源: https://blog.csdn.net/weixin_46719868/article/details/122450378