react 使用axios

Posted 1点

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了react 使用axios相关的知识,希望对你有一定的参考价值。

1.配置axios代理  使得axios  可以不写根路径

 

package.json

"proxy":"http://localhost:4000",

2.使用

 //发送请求
      axios.post("/api/user/register",newUser)
      .then(res=>{
             console.log(res.data);
      })
      .catch(err=>{
            this.setState({
              errors:err.response.data
            })
      })
      }

  

/api/user/register:是路径
newUser :发送的数据

 

以上是关于react 使用axios的主要内容,如果未能解决你的问题,请参考以下文章