vuejs local image preview, how to get the image src?
ComponentImagePreview.vue
<template>
<p class="card text-center" style="width: 16rem;">
<img class="card-img" :src="imgDataUrl" style="height: 16rem;">
<p class="card-footer text-muted">
<input type="file" id="image" name="image" @change="preview($event)">
</p>
</p>
</template>
<script>
export default {
data(){
return {
imgDataUrl: ''
}
},
methods: {
preview(event){
this.imgDataUrl = event.target.files;
}
}
}
</script>
Problem:
After clicking a picture, the picture cannot be displayed. src="[object File]"
is displayed in the browser debugging window. How should I write it? Can?
The following two ways of writing in the preview method will not work.
event.target.files
event.target.files[0]
event.target.value this is src
console.log(event.target.files) to see what the structure is like