错误
vue.js:6 Error: please transfer a valid prop path to form item!
原因
prop的内容和rules中定义的名称不一致! 应注意要一致
一般出现在table中form验证
代码
<el-form :model="serviceCheckForm" ref="serviceCheckForm" :rules="rules" size="small">
<el-table border :data="serviceCheckForm.serviceForm" ref="table" tooltip-effect="dark" size="mini" height="auto" width="1000">
<el-table-column min-width="80">
<template slot="header">
<p>
姓名
<span style="color:red;font-size:16px;">*</span>
</p>
</template>
<template slot-scope="scope" >
<el-form-item :prop="'serviceForm.'+scope.$index+'.name'" :rules="rules.name">
<el-select v-model="scope.row.name" placeholder="请选择" filterable>
<el-option v-for="item in members" :key="item.id" :label="item.name" :value="item.id">
</el-option>
</el-select>
</el-form-item>
</template>
</el-table-column>
<el-table-column min-width="120">
<template slot="header">
<p>
年龄
<span style="color:red;font-size:16px;">*</span>
</p>
</template>
<template slot-scope="scope">
<el-form-item :prop="'serviceForm.'+scope.$index+'.age'" :rules="rules.age">
<el-date-picker v-model="scope.row.enddate" type="date" placeholder="选择日期" style="width: 120px;">
</el-date-picker>
</el-form-item>
</template>
</el-table-column>
</el-table>
</el-form>
serviceCheckForm:{
},
rules: {
name: [{ required: true, message: "名字不能为空", trigger: "blur" }],
age: [{ required: true, message: "年龄不能为空", trigger: "blur" }],
},
async method(){
this.$refs.serviceCheckForm.validate(async valid => {
if (valid){
const loading = this.$loading(LOAD_STYLE);
try {
let res = await axios.post('api/xx/xx', this.serviceForm);
if (res.code === 200) {
}else {
}
} catch (e) {
this.$message.error('请求出错!', e.message);
}
// 关闭加载框
loading.close();
}
})
}
,
method2(index, row) {
this.serviceForm = deepCopy(row)
this.$set(this.serviceCheckForm,"serviceForm",this.serviceForm)
},
``