removed common method loadImage into mixin

This commit is contained in:
ManjaroOne666 2019-01-13 21:33:55 +00:00
parent a6eea72045
commit 53330304c7
2 changed files with 18 additions and 12 deletions

View File

@ -31,11 +31,13 @@
<script> <script>
import ThumbNav from '@/components/ThumbNav' import ThumbNav from '@/components/ThumbNav'
import imageLoader from '~/mixins/imageLoader.js'
export default { export default {
components: { components: {
ThumbNav ThumbNav
}, },
mixins: [ imageLoader ],
props: { props: {
isVisible: { isVisible: {
type: Boolean, type: Boolean,
@ -105,18 +107,6 @@ export default {
}) })
// TODO catch errors // TODO catch errors
}, },
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;
})
}
}, },
} }
</script> </script>

16
mixins/imageLoader.js Normal file
View File

@ -0,0 +1,16 @@
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;
})
}
}
}