簡體   English   中英

在問題上獲取反應組件方法

[英]fetch on react component method with problem

我試圖使用方法(saveUser)中的訪存進行API調用。 API運作良好,de方法運作良好,但我不知道PUT為什么無法運作。

這是代碼:

saveUser(user: IUser) {
  user = this.state.user;
  let userId = user._id;
  let url = `http://localhost:4200/api/update-user/${userId}`;

  fetch(url, {
             method: 'put',
             body: JSON.stringify(user),
             headers: {
               'Content-Type': 'application/json'
             }
       }).then(res => res.json())
       .catch(error => console.error('Error:', error))
       .then(response => console.log('Success:', response));
       debugger;
    };

這是所有代碼: manageUserPage

像這樣在您的request更改:

fetch(url, {
             method: 'PUT',
             body: JSON.stringify(user),
             headers: {
               'Content-Type': 'application/json'
             }

讓我知道問題是否仍然存在,並確保您已啟用CORS。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM