0

I am using v-for to loop through an array of objects. The list has a file input inside. On the change event of the file input, I am calling a method with a parameter. The problem is that the parameter value is not getting changed the same value is getting passed in all the file inputs.

<li v-for="(item, index) in this.ailment_details_form.items" :key="item.id">
                                            <input type="file" v-on:change="handleFileUpload(item.id)" />
                                            <label>@{{ item.id }}</label>
                                        </li>

This is the method.

handleFileUpload(i) {
    console.log(i);
    }

Below is the data.

ailment_details_form: {
            details: '',
            items: [
                { id: 1, text: "Item 1" },
                { id: 2, text: "Item 2" },
                { id: 3, text: "Item 3" }],
            files: [],
            urls: []
        }

Here item.id in handleFileUpload() method is always showing as 1. Where as inside label it is showing correctly. Please help.

7
  • 1
    Here you can see this error is not reproducible from the code shown: jsfiddle.net/sh0ber/vgy1b0a2 Commented Dec 18, 2020 at 18:41
  • @Akhilesh - It seems to work fine in this sandbox Commented Dec 18, 2020 at 18:41
  • Does this answer your question? VueJS: Input file selection event not firing upon selecting the same file, reset your uploader on each click Commented Dec 18, 2020 at 19:02
  • 1
    We can't reproduce it to identify the cause. You could try posting your whole app to codesandbox.io Commented Dec 19, 2020 at 14:54
  • 1
    @Dan I was able to fix the issue. The problem was with the label tag. The click event was fired by the label. It had the for attribute with same value. Thanks for your help. Commented Dec 19, 2020 at 16:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.