在使用antd时多层嵌套循环表单时校验会报如下错误:please transfer a valid name path to form item
原因:是循环体和字段无法绑定
解决如下:
<a-form> <div v-for="(item, index) in form.List" :key="index"> <a-form-item :name="['List',index,'userList',i,'name']" v-for="(ject, i) in item.userList" :key="i" :rules="[{ required: true, message: '必填' }]"> <a-input v-model:value="ject.name" /> </a-form-item> <div> </a-form>
嵌套表单校验可以这么理解:List[index].userList[i].name