I use v-for to dynamically generate components as follows
<template v-for="(n, index) in aUploadImgNum">
<v-upload class="goods_item_img" :key="index" :value="aUploadImgSrc[index]" @input="fnChangeImg($event, index)"></v-upload>
</template>
computed: {
//
aUploadImgNum() {
return this.aUploadImgSrc.length > 2 ? 3 : this.aUploadImgSrc.length + 1
},
},
methods: {
// aUploadImgSrc
fnChangeImg(src, index) {
console.log(index)
this.$set(this.aUploadImgSrc, index, src)
},
},
the effect is as follows
console.log(index)0,
console.log(index)0,
v-model,,$set,
{{ index }}0, 1
and add
to v-upload@click.native="test(index)"
test(index) {
console.log(index)
}
is also a normal output of 0,1
only the index of $emit ("input") in v-upload is always zero
is changed to $emit (" test") / @ test= "fnChangeImg ($event, index)")
the same is true for using n in (n, index) in aUploadImgNum, fixed to 1
I hope to have the advice of a great god