使用 PUT 请求在正文中传递一个空值

问题描述 投票:0回答:0

我正在执行 GET 请求以获取一些数据,然后在输入字段/文本区域中返回这些数据。我想更改 input/textarea 字段中的文本(如果我只是将文本更改为另一个文本,它就可以工作)并且能够将输入留空。这是行不通的。当我从 GET 请求中删除输入/文本区域字段中的文本时,它没有发生任何事情。该请求有效,我没有收到任何错误,它只是没有发生任何事情。

我的 PUT 请求:

const handlePut = () => {
    fetch(URL, {
      method: "PUT",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        // inputValue: inputValue,
        article: article || product.article,
      }),
    })
      .then((response) => response.json())
      .then((data) => {
        console.log(data);
      })
      .catch((error) => console.error(error));
  };

我的输入:

      <textarea
              defaultValue={product.article}
              onChange={handleArticleChange}
              placeholder={article || product.article}
            />

“product.article”是我从 GET 请求中获取数据的方式,“article”来自 useState。

我试图在邮递员中将文章值留空,这工作正常。

reactjs jsx put
© www.soinside.com 2019 - 2024. All rights reserved.