element 表单验证 el-form-item里面验证两个select 必填,select 值绑定为对象时如何验证必填
el-form-item 里面有多个select 或者input :
<el-form-item label="学段学科:" required> <div class="diasubject"> <el-form-item prop="stage" :rules="[{ required: true, message: '请选择学段', trigger: 'change' }]"> <el-select v-model="Newtextbooks.cinfigForm.stage" placeholder="请选择学段"> <el-option v-for="item in diaFormQArr.stageArr" :key="item.code" :label="item.name" :value="item.code"> </el-option> </el-select> </el-form-item> <el-form-item prop="subject" :rules="[{ required: true, message: '请选择学科', trigger: 'change' }]"> <el-select v-model="Newtextbooks.cinfigForm.subject" placeholder="请选择学科"> <el-option v-for="item in diaFormQArr.subjectArr" :key="item.code" :label="item.name" :value="item.code"> </el-option> </el-select> </el-form-item> </div> </el-form-item>
当select 选中值绑定为对象时,el-form-item 上面的prop 只需要 监听 select 的 v-model 绑定的 stage对象里面某个属性是否有值,这样就可以验证必填