接口报错 cannot read properties of undefined (reading 'then')
问题
遇到一个很奇怪的问题,接口返回值为 undefined
代码如下:
// 归档/解档
archiveAction(actionType, row) {
const ids = row && row.id ? row.id : this.ids;
const tip = row && row.id ? `“${row.projectName}”` : "所勾选的";
const actionLabel = actionType === "archive" ? "归档" : "解档";
this.$modal
.confirm(`是否确认${actionLabel}${tip}项目?${actionLabel}后可编辑`)
.then(() => {
this.$modal.loading(`正在${actionLabel},请稍后……`);
if (actionType === "archive") {
project.archiveProject(ids).then((res) => {
console.log({ res });
this.$modal.msgSuccess(`${actionLabel}成功`);
this.getList();
});
} else {
project.unArchiveProject(ids).then((res) => {
console.log({ res });
this.$modal.msgSuccess(`${actionLabel}成功`);
this.getList();
});
}
})
.catch((err) => {
console.log(err);
})
.finally(() => {
this.$modal.closeLoading();
});
},
解决
后来发现是接口文档封装有问题:
// 解档:
// 错误写法
const unArchiveProject = (ids) => {
request.put("/project/project/reArchive?ids=" + ids);
};
// 正确写法
const unArchiveProject = (ids) => request.put("/project/project/reArchive?ids=" + ids);
参考链接
本文来自博客园,作者:shayloyuki,转载请注明原文链接:https://www.cnblogs.com/shayloyuki/p/18298940
posted on 2024-07-12 17:00 shayloyuki 阅读(197) 评论(0) 编辑 收藏 举报