[英]how to solve console log issue in chrome browser
I'm getting data from an API and initially when console it in fetchData
function it works but when console it in fetchDailyData
function and call this function in another component it didn't work.我从API获取数据,并开始时安慰它
fetchData
功能,它的工作原理,但是当控制台它fetchDailyData
功能和调用这个函数在其他组件没有奏效。
How can I solve this issue?我该如何解决这个问题?
import axios from 'axios';
const url = `https://covid19.mathdro.id/api`;
export const fetchData = async () => {
try {
const { data: { confirmed, recovered, deaths, lastUpdate }} = await axios.get(url);
return { confirmed, recovered, deaths, lastUpdate };
} catch (error) {
}
}
export const fetchDailyData = async () => {
try {
const { data } = await axios.get(`${url}/daily`);
console.log(data); // <<==>> chrome browser is not showing this console log
// fetchDailyData function called in another component
} catch (error) {
}
}
Calling fetchDailyData
function in another component when I call console.log
, I can't see the data in console of my browser当我调用
console.log
时在另一个组件中调用fetchDailyData
函数,我在浏览器的控制台中看不到数据
const Chart = () => {
const [dailyData, setDailyData] = useState({});
useEffect(() => {
const fetchApi = async () => {
setDailyData(await fetchDailyData());
}
console.log(dailyData);
fetchApi();
});
};
https://covid19.mathdro.id/api/daily
which is your url in fetchDailyData
doesn't return any data currently at all. https://covid19.mathdro.id/api/daily
这是您在fetchDailyData
中的网址, fetchDailyData
根本不返回任何数据。
I suppose you have to check if this backend still available.我想你必须检查这个后端是否仍然可用。 And it is a good practice to check the response status (normally it should return statusCode 200) in response callback.
在响应回调中检查响应状态(通常它应该返回 statusCode 200)是一个很好的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.