N
Nuxt6mo ago
reinacchi

File Upload Preview

how would i put a preview image upon uploading it?
6 Replies
reinacchi
reinacchi6mo ago
here's my code:
Muhammad Mahmoud
First you should use $fetch instead of useFetch as this is a user-interaction based. For Image previews you create a URL from your file value and then use that in your <template>
<script setup lang="ts">
const file = ref<FileList | null>(null);
const imagePreview = computed(() =>
file.value ? URL.createObjectURL(file.value) : false
)
</script>

<template>
<p> Uploaded Image Preview </p>
<img src="imagePreview" />
</template>
<script setup lang="ts">
const file = ref<FileList | null>(null);
const imagePreview = computed(() =>
file.value ? URL.createObjectURL(file.value) : false
)
</script>

<template>
<p> Uploaded Image Preview </p>
<img src="imagePreview" />
</template>
reinacchi
reinacchi6mo ago
it gives me this error
No description
Muhammad Mahmoud
You may want to log values to see what's wrong. Maybe you need to pass file.value[0] for example
reinacchi
reinacchi6mo ago
i've got it worked. thank you :D
Want results from more Discord servers?
Add your server