使用 Axios 提交请求 |反应,Redux [英] Put request with Axios | React, Redux

查看:20
本文介绍了使用 Axios 提交请求 |反应,Redux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 Axios 发出一个 put 请求,到目前为止我已经在我的操作中实现了这一点:

I want to make a put request with Axios and I got this inside of my action so far:

export function updateSettings(item) {
  return dispatch => {
    console.log(item)
    return axios.put(`/locks`).then(response => {
      console.log(response)
    })
  }
}

当我 console.log item 时,我可以看到我在该对象内的输入框中输入的所有内容,但后来我得到 404.我知道我有那个 URI.有谁知道如何解决这个问题?

When I console.log item I can see all of things I've typed in my input boxes inside of that object, but later I get 404. I know that I have that URI. Does anyone know how to troubleshoot this problem?

推荐答案

PUT 请求需要资源标识符(例如 id)和要更新的有效负载.您似乎没有确定要更新的资源,因此是 404.

A PUT request requires an identifier(e.g id) for the resource and the payload to update with. You seem not to be identifying the resource you want to update, hence 404.

你需要一个 iditem 像这样.

you'd need an id and item like this.

export function updateSettings(id, item) {
  return dispatch => {
    console.log(item)
    return axios.put(`/locks/${id}`, item).then(response => {
        console.log(response)
    })
  }
}

这篇关于使用 Axios 提交请求 |反应,Redux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆