1.首先在动态添加的表单绑定值,直接上代码
......
<div v-for="(i , index) in addForm.familys">
<el-form-item label="姓名"
:prop="'family' + index + 'name'"
:rules="[{max:40,message:'姓名不能超过40个字符',trigger:'change'}]">
<el-input v-model="i.name"></el-input>
</el-form-item>
<el-form-item label="年收入"
:prop="'family' + index + 'income'"
:rules="moreRules.income">
<el-input v-model="i.income"></el-input>
</el-form-item>
</div>
......
2.js里面代码
data(){
return{
addForm:{
familys:[
{name:'',income:''}
]
},
moreRelus:{
income:[
{
validator:(rule,valued,callback)=>{
if(valued){
let checkedIncome=/^[1-9[0-9]{0,14}$]/;
if(checkedIncome.test(valued)){
callback();
}else{
callback('请输入大于零且最多15位的整数!');
}
}else{
callback();
}
},
trigger:'change'
}
],
}
}
}