本文介绍了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数据
发布评论