если вы хотите весь загрузчик страниц, чтобы вы могли управлять его видом.Вы можете непосредственно показать скрыть загрузчик из вашего метода HTTP-вызова.
HttpRequests.js
'use strict';
function isLoaderManage() {
let x = document.getElementById("loader");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
const request = {
get: (url) => {
return fetch(url)
.then((resp) => {
isLoaderManage();
return resp.json();
})
.then((resp) => {
isLoaderManage();
return resp;
}).catch((err) => {
isLoaderManage();
return err;
});
},
}
export { request };
API.js
'use strict';
import { request } from './HttpRequests';
const API = {
getSongs: (URL) => request.get(URL),
}
export { API };
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/" />
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="loader"></div>
<div id="root"></div>
</body>
</html>
index.css
#loader {
position: fixed;
width: 100%;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(255, 255, 255, 0.7);
z-index: 9999;
}
@-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
#loader::after {
content: "";
display: block;
position: absolute;
left: 48%;
top: 40%;
width: 40px;
height: 40px;
border-style: solid;
border-color: black;
border-top-color: transparent;
border-width: 4px;
border-radius: 50%;
-webkit-animation: spin 0.8s linear infinite;
animation: spin 0.8s linear infinite;
}