在父组件内,请求接口,返回表单结构,并将其处理为自己可用的结构,有表单验证也可在此时处理好:
接口名().then(res=>{
res.data.map(i=>{
let pla = ''
if(i.placeholder == ''){
if(i.type == 'input'){
pla = `请输入${i.prop}`
}else if(i.type == 'date'){
pla = `请选择${i.prop}`
}
}
this.formData.push({
label: i.prop,
type: i.type,
maxlength: null,
placeholder: pla,
prop: i.label
})
that.rules[i.label] = [{ required: true, message: pla, trigger: i.type == 'input' ? 'blur' : 'change' }]
})
})
****!!!!! 注意这个是时候不要处理form表单的model直接给他赋值为空即可,否则会出现输入框输值,页面无变化,验证不通过,打印却会有值的情况 *******
父组件给ruleForm的值为{}
<template>
<el-form :inline="true" :model="ruleForm" ref="ruleForm" :rules="rules" label-position="right" label-width="76" class="demo-ruleForm">
<el-row&