如何在获取api时添加加载动画(普通javascript)
所以我从football-data.org制作了这个web应用程序 我想在api中的模板显示到浏览器窗口之前,在异步步骤运行时制作一个加载动画 这是fetchapi的代码如何在获取api时添加加载动画(普通javascript),javascript,api,fetch,single-page-application,progressive-web-apps,Javascript,Api,Fetch,Single Page Application,Progressive Web Apps,所以我从football-data.org制作了这个web应用程序 我想在api中的模板显示到浏览器窗口之前,在异步步骤运行时制作一个加载动画 这是fetchapi的代码 const fetchAPI = (url) => { return fetch(url, { headers: { "X-Auth-Token": API_KEY, }, }) .then((res) => { if (res.statu
const fetchAPI = (url) => {
return fetch(url, {
headers: {
"X-Auth-Token": API_KEY,
},
})
.then((res) => {
if (res.status !== 200) {
console.log(`Error: ${res.status}`);
return Promise.reject(new Error(res.statusText));
} else {
return Promise.resolve(res);
}
})
.then((res) => res.json())
.catch((err) => {
console.log(err);
});
};
function getStandingJer() {
if ("caches" in window) {
caches.match(ENPOINT_JER).then(function (response) {
if (response) {
response.json().then(function (data) {
console.log("Competition Data: " + data);
showStanding(data);
});
}
});
}
fetchAPI(ENPOINT_JER)
.then((data) => {
showStanding(data);
})
.catch((error) => {
console.log(error);
});
}
function getStandingBel() {
if ("caches" in window) {
caches.match(ENPOINT_BEL).then(function (response) {
if (response) {
response.json().then(function (data) {
console.log("Competition Data: " + data);
showStanding(data);
});
}
});
}
fetchAPI(ENPOINT_BEL)
.then((data) => {
showStanding(data);
})
.catch((error) => {
console.log(error);
});
}
我正在使用gif加载动画,我之前已经尝试过了,它给了我控制台一个承诺错误