解决v-for中遍历多个el-select时下拉选择框同步选择问题 div v-for=itemindex in detailInfo key=index label=itemname value=itemid div class=line_xudiv div class=p_title pitemnamep
在v-for循环中,使用v-model绑定一个数组来存储每个下拉选择框的值,例如:v-model="thirdSelectValue[optionIndex]"。然后在changeSelect方法中,根据当前选择框的索引,更新所有下拉选择框的值。具体实现如下:
- 在data中定义一个空数组thirdSelectValue来存储每个下拉选择框的值:
data() { return { thirdSelectValue: [] } }
- 在changeSelect方法中,遍历所有下拉选择框,根据当前选择框的索引更新其他下拉选择框的值:
changeSelect(optionIndex) { const value = this.thirdSelectValue[optionIndex] this.detailInfo.forEach(item => { item.children.forEach((item2, index) => { if (index !== optionIndex) { this.$set(this.thirdSelectValue, index, value) } }) }) }
这样就可以实现多个下拉选择框的同步选择了。
原文地址: https://www.cveoy.top/t/topic/beta 著作权归作者所有。请勿转载和采集!