#137 - create single image component and add download image function

This commit is contained in:
isUnknown 2025-02-26 15:12:15 +01:00
parent 1cd55b98d6
commit 1ed7aa9c5b
5 changed files with 63 additions and 33 deletions

View file

@ -0,0 +1,29 @@
<template>
<figure>
<img :src="file.url" alt="" />
</figure>
</template>
<script setup>
import { storeToRefs } from 'pinia';
import { useVirtualSampleStore } from '../../../stores/virtualSample';
import { watch } from 'vue';
const { file } = defineProps({
file: Object,
});
const { isDownloadTriggered } = storeToRefs(useVirtualSampleStore());
// Download image
watch(isDownloadTriggered, (newValue) => {
if (!newValue) return;
const downloadNode = document.createElement('a');
downloadNode.setAttribute('href', file.source);
downloadNode.setAttribute('download', '');
document.body.appendChild(downloadNode);
console.log(downloadNode);
downloadNode.click();
document.body.removeChild(downloadNode);
});
</script>