#137 - create single image component and add download image function
This commit is contained in:
parent
1cd55b98d6
commit
1ed7aa9c5b
5 changed files with 63 additions and 33 deletions
29
src/components/project/virtual-sample/SingleImage.vue
Normal file
29
src/components/project/virtual-sample/SingleImage.vue
Normal 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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue