marc-leopold/mixins/imageLoader.js

17 lines
358 B
JavaScript

export default {
methods: {
loadImage(url) {
return new Promise( (resolve, reject) => {
const img = new Image()
img.addEventListener('load', e => resolve(img));
img.addEventListener('error', () => {
reject(new Error(`Failed to load image URL: ${url}`));
});
img.src = url;
})
}
}
}