React Native应用程序不会获取api数据

编程入门 行业动态 更新时间:2024-10-13 12:20:51
本文介绍了React Native应用程序不会获取api数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的React Native应用程序不会获取或获取api数据.它不会控制台日志数据,甚至不会出错.我已经尝试过使用fetch和axios.

My React Native app won't fetch or get api data. It will not console log data or even an error. I've tried using fetch and axios.

获取方法:

export default class List extends React.Component { commponentDidMount() { fetch(URL) .then((response) => response.json()) .then((responseData) => { console.log(responseData); }) .catch(error => { console.log(error); }); } }

axios方法:

export default class List extends React.Component { commponentDidMount() { axios.get(URL) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); } }

我不确定是什么问题,也无法在线找到解决方案.

I'm not sure what the problem is and I can't find a solution online.

推荐答案

请检查拼写功能 componentDidMount 并尝试下面的示例代码.

Please do check spelling function componentDidMount And try below sample code I have.

componentDidMount() { let URL = `...`; fetch(URL) .then(res => res.json()) .then(res => { console.log('response:', res.data); }); }

希望这会有所帮助.

更多推荐

React Native应用程序不会获取api数据

本文发布于:2023-10-11 14:24:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481959.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   数据   React   Native   api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!