2021-05-23 05:04:19 +00:00
|
|
|
<template>
|
2021-05-24 18:12:46 +00:00
|
|
|
<v-img
|
|
|
|
v-if="!fallBackImage"
|
2021-08-02 03:24:47 +00:00
|
|
|
:height="height"
|
2021-05-24 18:12:46 +00:00
|
|
|
:src="getImage(slug)"
|
2021-08-02 03:24:47 +00:00
|
|
|
@click="$emit('click')"
|
2021-05-24 18:12:46 +00:00
|
|
|
@load="fallBackImage = false"
|
|
|
|
@error="fallBackImage = true"
|
|
|
|
>
|
|
|
|
<slot> </slot>
|
|
|
|
</v-img>
|
2021-08-02 03:24:47 +00:00
|
|
|
<div v-else class="icon-slot" @click="$emit('click')">
|
2021-05-24 18:12:46 +00:00
|
|
|
<v-icon color="primary" class="icon-position" :size="iconSize">
|
|
|
|
{{ $globals.icons.primary }}
|
|
|
|
</v-icon>
|
2021-08-02 03:24:47 +00:00
|
|
|
<slot> </slot>
|
2021-05-23 05:04:19 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-08-03 06:15:11 +00:00
|
|
|
import { useApiSingleton } from "~/composables/use-api";
|
2021-05-23 05:04:19 +00:00
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
tiny: {
|
|
|
|
type: Boolean,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
small: {
|
|
|
|
type: Boolean,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
large: {
|
|
|
|
type: Boolean,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
iconSize: {
|
2021-08-02 03:24:47 +00:00
|
|
|
type: [Number, String],
|
2021-05-23 05:04:19 +00:00
|
|
|
default: 100,
|
|
|
|
},
|
|
|
|
slug: {
|
2021-08-02 03:24:47 +00:00
|
|
|
type: String,
|
2021-05-23 05:04:19 +00:00
|
|
|
default: null,
|
|
|
|
},
|
2021-05-23 23:05:39 +00:00
|
|
|
imageVersion: {
|
2021-08-02 03:24:47 +00:00
|
|
|
type: String,
|
2021-05-23 23:05:39 +00:00
|
|
|
default: null,
|
|
|
|
},
|
2021-05-23 05:04:19 +00:00
|
|
|
height: {
|
2021-08-02 03:24:47 +00:00
|
|
|
type: Number,
|
2021-05-23 05:04:19 +00:00
|
|
|
default: 200,
|
|
|
|
},
|
|
|
|
},
|
2021-08-02 03:24:47 +00:00
|
|
|
setup() {
|
2021-08-03 06:15:11 +00:00
|
|
|
const api = useApiSingleton();
|
2021-08-02 03:24:47 +00:00
|
|
|
|
|
|
|
return { api };
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fallBackImage: false,
|
|
|
|
};
|
|
|
|
},
|
2021-05-23 05:04:19 +00:00
|
|
|
computed: {
|
|
|
|
imageSize() {
|
|
|
|
if (this.tiny) return "tiny";
|
|
|
|
if (this.small) return "small";
|
|
|
|
if (this.large) return "large";
|
|
|
|
return "large";
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
slug() {
|
|
|
|
this.fallBackImage = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2021-05-23 23:05:39 +00:00
|
|
|
getImage(slug) {
|
2021-05-23 05:04:19 +00:00
|
|
|
switch (this.imageSize) {
|
|
|
|
case "tiny":
|
2021-08-02 03:24:47 +00:00
|
|
|
return this.api.recipes.recipeTinyImage(slug, this.imageVersion);
|
2021-05-23 05:04:19 +00:00
|
|
|
case "small":
|
2021-08-02 03:24:47 +00:00
|
|
|
return this.api.recipes.recipeSmallImage(slug, this.imageVersion);
|
2021-05-23 05:04:19 +00:00
|
|
|
case "large":
|
2021-08-02 03:24:47 +00:00
|
|
|
return this.api.recipes.recipeImage(slug, this.imageVersion);
|
2021-05-23 05:04:19 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.icon-slot {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.icon-slot > div {
|
2021-07-09 22:33:23 +00:00
|
|
|
top: 0;
|
2021-05-23 05:04:19 +00:00
|
|
|
position: absolute;
|
|
|
|
z-index: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.icon-position {
|
|
|
|
opacity: 0.8;
|
|
|
|
display: flex !important;
|
|
|
|
position: relative;
|
|
|
|
margin-left: auto !important;
|
|
|
|
margin-right: auto !important;
|
|
|
|
}
|
|
|
|
</style>
|