Image.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <main>
  3. <v-img
  4. :src="imageLoaded"
  5. :lazy-src="require(`/assets/images/byDefault/${imageByDefault}`)"
  6. :min-height="height"
  7. :min-width="width"
  8. aspect-ratio="1"
  9. >
  10. <template v-slot:placeholder>
  11. <v-row
  12. class="fill-height ma-0"
  13. align="center"
  14. justify="center"
  15. >
  16. <v-progress-circular
  17. indeterminate
  18. color="grey lighten-1"
  19. ></v-progress-circular>
  20. </v-row>
  21. </template>
  22. </v-img>
  23. </main>
  24. </template>
  25. <script lang="ts">
  26. import {defineComponent, ref, Ref, useContext, useFetch} from '@nuxtjs/composition-api'
  27. import {QUERY_TYPE} from "~/types/enums";
  28. export default defineComponent({
  29. props: {
  30. id: {
  31. type: Number,
  32. required: false
  33. },
  34. imageByDefault: {
  35. type: String,
  36. required: false,
  37. default: 'default_pic.jpeg'
  38. },
  39. height: {
  40. type: Number,
  41. required: false,
  42. default: 0
  43. },
  44. width: {
  45. type: Number,
  46. required: false,
  47. default: 0
  48. }
  49. },
  50. fetchOnServer: false,
  51. setup(props) {
  52. const {$dataProvider, $config} = useContext()
  53. const imageLoaded: Ref<String> = ref('')
  54. useFetch(async () => {
  55. try{
  56. if(props.id){
  57. imageLoaded.value = await $dataProvider.invoke({
  58. type: QUERY_TYPE.IMAGE,
  59. baseUrl: $config.baseURL_Legacy,
  60. imgArgs: {
  61. id: props.id,
  62. height: props.height,
  63. width: props.width
  64. }
  65. })
  66. }else
  67. throw new Error('id is null')
  68. }catch (e){
  69. imageLoaded.value = require(`/assets/images/byDefault/${props.imageByDefault}`)
  70. }
  71. }
  72. )
  73. return {
  74. imageLoaded
  75. }
  76. }
  77. })
  78. </script>