Element UI表單中數(shù)組循環(huán)驗(yàn)證必填方法
表單內(nèi)有部分?jǐn)?shù)據(jù)是通過(guò)數(shù)組循環(huán)展示出來(lái)的,需要對(duì)循環(huán)出來(lái)的表單進(jìn)行驗(yàn)證,方式如下:
1 <div class="material-list" v-for="(item,index) in model.materialList" :key="index"> 2 <el-form-item label="類型" :prop="`materialList.${index}.materialType`" :rules="{ required: true, message: '請(qǐng)選擇類型',trigger: 'change'}"> 3 <el-select v-model="item.materialType" placeholder="請(qǐng)選擇類型" style="width:230px" @change="Change" :remote-method="remoteMethodmaterialType" filterable remote> 4 <el-option 5 v-for="(item,index) in materialTypeList" 6 :key="index" 7 :label="item" 8 :value="item"> 9 </el-option> 10 </el-select> 11 </el-form-item> 12 </div>
解析:首先循環(huán)model里邊的數(shù)組materialList,然后在el-form-item標(biāo)簽的prop驗(yàn)證中添加驗(yàn)證的字段為materialList數(shù)組下的字段名(通過(guò)index索引來(lái)獲取)
數(shù)據(jù)格式,如下:
data(){ return{ model: { billId: '',picker: '',remark: '', materialList: [ {materialType: '',brand:'',material: '',unit:'',specificationModel:'',materialId: '',actualNumber:''}, ] }, }
本文來(lái)自博客園,作者:四川郭富城,轉(zhuǎn)載請(qǐng)注明原文鏈接:http://www.rzrgm.cn/Andy-Blog/p/18925177

浙公網(wǎng)安備 33010602011771號(hào)