baidu / baidu/amis

fetcher函数中method为delete时,跟config中的method不一致

Open
#5,348 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
18.9k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

#### 实现场景:
在做删除操作时,发现请求为post,定位到fetcher中,发现config跟method不一致。config中的method为post,而真实的method为delete

#### 存在的问题:
method为delete时,跟config中的method不一致

#### 当前方案:

```
//delete按钮
{
label: "删除",
type: "button",
level: "link",
actionType: "ajax",
className: "text-danger",
disabledOn: "this.id < 0",
confirmText: "确认要删除?",
// eslint-disable-next-line no-template-curly-in-string
api: "delete:/api/v1/amis/list/${id}",
},
// 实现的fetcher
fetcher: ({
url, // 接口地址
method, // 请求方法 get、post、put、delete
data, // 请求数据
responseType,
config, // 其他配置
headers, // 请求头
}: any) => {
const axiosIstance = axios.create();
config = config || {};
config.withCredentials = true;
// eslint-disable-next-line no-unused-expressions
responseType && (config.responseType = responseType);

if (config.cancelExecutor) {
config.cancelToken = new (axios as any).CancelToken(
config.cancelExecutor
);
}

config.headers = headers || {};

if (method !== "post" && method !== "put" && method !== "patch") {
console.log("method", method); //method为delete
console.log("config", config); //config为
return axiosIstance.request({ method, url, ...config });
}
....
```
其中,method的值为 `delete`,config中的method为`post`为:
```
errorMessage: undefined
headers: {}
method: "post"
successMessage: undefined
withCredentials: true
[[Prototype]]: Object
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the fetcher entry point and trace the branch handling methods other than post, put, and patch. Inspect how axios.create().request receives method and config, then verify that a delete action does not retain the conflicting post method in the request configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.