如何从reactjs发出Http请求?

我在ToDo应用程序中将react

js用作前端,将zf3用作后端。我把所有的React文件夹和文件都放在Zend项目的公共文件夹中。到目前为止,它只是简单的应用程序,没有数据库连接。现在,我想添加Db来存储任务。但是作为一个新手,我不知道如何使Http请求进行编辑删除和添加任务。请举例说明。任何帮助将不胜感激。谢谢。

回答:

我使用axios。它允许您设置一些默认配置,这样您就不必对每个请求都这样做:

axios.defaults.headers.common.Authorization = "my-awesome-token";

axios.defaults.baseURL = http://www.somehost.com/api;

...

axios.get('/people')

.then(response => handleResponse(response))

.catch(error => handleError(error))

// actually shoots to http://www.somehost.com/api/people with Authorization header

以上是 如何从reactjs发出Http请求? 的全部内容, 来源链接: utcz.com/qa/422080.html

回到顶部