Element el-form根据选择条件动态控制表单必填项

业务场景:当select=A时 C非必填 反之当select=B时C必填
Element el-form根据选择条件动态控制表单必填项

Element el-form根据选择条件动态控制表单必填项
代码实现

  <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' }],
      },
上一篇:Vue学习笔记01


下一篇:win10 SecoClient连接“提示用户与对方建立连接超时,配置错误或网络故障”