marc-leopold/app/mixins/imageLoader.js

17 lines
358 B
JavaScript
Raw Normal View History

2019-02-24 16:42:27 +00:00
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;
})
}
}
}