refactor(image link mixin): adds image link mixin

This commit is contained in:
Cameron 2020-09-05 18:10:39 +01:00
parent dfa4c6c083
commit d2f1699a59
2 changed files with 18 additions and 7 deletions

15
mixins/imageHelper.ts Normal file
View File

@ -0,0 +1,15 @@
const imageHelper = {
methods: {
/**
* returns a URL with the link to the image
* @param id itemId to get image for
* @param type type of image (primary/backdrop)
* @returns URL of the link to the image
*/
getImageLink(id: string, type: string): string {
return `${this.$axios.defaults.baseURL}/Items/${id}/Images/${type}`;
}
}
};
export default imageHelper;

View File

@ -1,6 +1,6 @@
<template>
<div>
<v-img :src="imageLink(item.Id, 'backdrop')"></v-img>
<v-img :src="getImageLink(item.Id, 'backdrop')"></v-img>
<h1>{{ item.Name }}</h1>
<p>{{ item.Overview }}</p>
<v-btn color="primary">Play {{ item.Type }}</v-btn>
@ -10,8 +10,10 @@
<script lang="ts">
import Vue from 'vue';
import imageHelper from '~/mixins/imageHelper';
export default Vue.extend({
mixins: [imageHelper],
data() {
return {
item: {}
@ -27,12 +29,6 @@ export default Vue.extend({
});
this.item = Item.data.Items[0];
},
methods: {
imageLink(id: string, type: string) {
const url = `${this.$axios.defaults.baseURL}/Items/${id}/Images/${type}`;
return url;
}
}
});
</script>