码迷,mamicode.com
首页 > 移动开发 > 详细

react 使用axios

时间:2019-01-27 13:01:53      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:post   localhost   sha   tst   .post   span   error   oca   json   

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

标签:post   localhost   sha   tst   .post   span   error   oca   json   

原文地址:https://www.cnblogs.com/guangzhou11/p/10325843.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!