const list = [
"./img.png",//
"//be-fe.github.io/static/images/iSlider-card/10.jpg",//
"./load.gif",//
"//be-fe.github.io/static/images/iSlider-card/12.jpg",//
null,//
"//be-fe.github.io/static/images/iSlider-card/17.jpg",//
];
const placeholder = "";
const loadError = "";
const render = () => {
let endSrc = placeholder;
let imgList = [];
list.forEach((ele) => {
if(ele){
const image = new Image();
image.src = ele;
image.onload = () => {
endSrc = ele;
};
image.onerror = () => {
endSrc = loadError;
};
}
imgList.push(endSrc);
});
// html onload onerror[loaderror ]
return imgList;
}
console.log(render())
// ["", "", "", "", "", ""]
// ["./img.png", "", "./load.gif", "", "", ""]
I have asked similar questions before, but they are not satisfied and there is no need!