1、调用子组件校验的方法时报错:
2、代码:
父组件:
// 新增修改弹窗确定按钮
async handleOk() {
let url = this.$url.SITE_MANAGE_LIST_ADD;
let method = "str";
let formData = await this.$refs.addCont.getValues();
console.log(formData);
// 判断是否在新增修改有选中?
if(formData && formData.selectedRowKeys.length > 0) {
// 处理参数
} else {
this.$message.error('请选择站点!');
return
}
if (this.isEdit) {
url = this.$url.SITE_MANAGE_LIST_PUT;
method = "put";
}
if(formData) {
this.addPop = false;
this.dataLoad = true;
let res = await this.$http(url, method, formData);
this.dataLoad = false;
if (res.data.code == 0) {
this.getTabData(this.form.getFieldsValue());
if (method == "str") {
this.$message.success("新增成功");
}
if (method == "put") {
this.$message.success("修改成功");
}
}
this.$refs.addCont.resetValues();
}
},
子组件:
getValue() {
return new Promise((resolve, reject) => {
this.form.validateFields(err => {
if(!err) {
let data = this.form.getFieldsValue();
data.selectedRowKeys = this.selectedRowKeys; // 选中的id集合
resolve(data);
} else {
reject(err)
}
})
})
},
3、排除发现调用方法名错了,getValue少了个s
悄悄努力,惊艳自己!