美文网首页
react ajax

react ajax

作者: hk_faith | 来源:发表于2020-03-03 15:21 被阅读0次

简介

1,react 本身只关注界面,并不包含 ajax 请求的代码
2,前端需要应用通过 ajax 请求与后台进行交互(json数据)
3,react 应用中需要集成第三方 ajax库

常用的ajax 请求库

1,jQuery :比较重,如果需要另外引入不建议使用
2,fetch L:原生函数,但老版本浏览器不支持
3,axios :轻量级,建议使用
a, 封装 XmlHttpRequest 对象的 ajax
b, promise 风格
c, 可以用在浏览器端和node 服务器端

使用

文档

Get 请求

axios.get('/user?ID=12345') 
.then(function (response) {
 console.log(response); 
})
.catch(function (error) { 
console.log(error); 
});

axios.get('/user', { params: { ID: 12345 } })
.then(function (response) { 
console.log(response);
 })
.catch(function (error) { 
console.log(error); 
});

Post 请求

axios.post('/user', { 
firstName: 'Fred', 
lastName: 'Flintstone' 
})
.then(function (response) { 
console.log(response);
 })
.catch(function (error) { 
console.log(error);
 });

相关文章

  • (四)React请求接口数据

    React请求接口数据 一、React ajax React本身只关注于界面, 并不包含发送ajax请求的代码,前...

  • react-rxjs-ajax

    react使用rxjs的ajax请求方式

  • React学习补充

    React 网络请求 方法一 原生请求,react自带的fetch请求方式: 方法二 ajax请求,react通过...

  • react最佳实践

    看到石墨的react文档。提到http://andrewhfarmer.com/react-ajax-best-p...

  • React中的“ajax”

    React没有ajax模块 集成其他的js库(如axios/fetch/jquery),发送ajax请求axios...

  • React ajax

    1. 用到两个工具, axios 和 lodash

  • react ajax

    简介 1,react 本身只关注界面,并不包含 ajax 请求的代码2,前端需要应用通过 ajax 请求与后台进行...

  • 如何在React中做Ajax 请求?

    如何在React中做Ajax 请求? 首先:React本身没有独有的获取数据的方式。实际上,就React而言,它甚...

  • React入门教程(9)Ajax与React的上下文

    ajax请求 react的组件中,一般我们在 componentDidMount事件中做ajax请求,并获得数据后...

  • react 第四章—— ajax

    1.理解: React本身只关注于界面, 并不包含发送ajax请求的代码前端应用需要通过ajax请求与后台进行交互...

网友评论

      本文标题:react ajax

      本文链接:https://www.haomeiwen.com/subject/zothlhtx.html