Reputation: 4668
I have created a button that adds file inputs, and would like to display thumbnails for each input.
However I am having issues accessing the custom binding :inputnum
on the input
.
When I console.log(event.target)
(see arrow), I get
<input data-v-0e14f7d0 inputnum="1" type="file">
Which is expected, however, console.log(event.target.inputnum)
returns undefined.
How do I access inputnum
on the input?
Is there a simpler approach to this?
<template>
<div>
<button @click="addUploader">Add Image</button>
<div v-for="n in count" :key="n">
<input :inputnum="n" type="file" @change="updateThumbnail">
<img :src="images[n]">
</div>
<button @click="submitImages">Submit Images</button>
</div>
</template>
<script>
export default {
data () {
return {
count: 0,
images: {}
}
},
methods: {
addUploader() {
this.count++
},
updateThumbnail(event) {
console.log(event.target) <-------------------------
const imgFile = event.srcElement.files[0]
var reader = new FileReader();
reader.readAsDataURL(imgFile);
reader.onload = () => {
this.images[event.target.inputnum] = reader.result
}
}
}
}
Upvotes: 0
Views: 90
Reputation: 5955
that would be
console.log(event.target.getAttribute('inputnum'));
>> "1"
that is: by using the getAttribute
method of the element.
Upvotes: 1