[Vuejs]-Vue 2 js replacing 1 image from v-for img src

0👍

You’re passing the index to the event handler and calling it e so e.target.files is probably null.

Change this

<input type="file" id="file-upload" accept="image/png, image/jpg ,image/jpeg" @change="onFileChange(index)"/>

To this

<input type="file" id="file-upload" accept="image/png, image/jpg ,image/jpeg" @change="onFileChange($event, index)"/>

And this

onFileChange (e) {
      this.file = e.target.files[0]
      this.bannerArray[0].banner_url = URL.createObjectURL(this.file)
    }

to this

onFileChange (e, i) {
      this.file = e.target.files[0]
      this.bannerArray[i].banner_url = URL.createObjectURL(this.file)
    }

Leave a comment