function loadImageAsync(url) {
return new Promise(function(resolve, reject) {
var image = new Image();
image.onload = function() {
resolve(image);
};
image.onerror = function() {
reject(new Error('Could not load image at ' + url));
};
image.src = url;
});
}
What I want to know is how to use this method? I entered URL
, and then obtained the object image in then
? But I tested it, but there was no response!
When called like this, the parameter of then is the parameter of resolve, which is the image object. The function can be realized by appending this object to p
This is the final result
This is the console
Yes, I tried it in the browser: