数组循环出来的盒子v-model绑定相同的值时我们需要这样做 直接上代码 效果看封面
<el-form-item label=”选择:” prop=”unit”>
<div
v-for=”(item, index) in controlNumber”
:id=”getid(index)”
:key=”item.id”
class=”materials-input”
>
<el-col>
<el-select
v-model=”values[index]”
:name=”‘name’ + index”
placeholder=”请选择材料”
>
<el-option
:label=”item.materialName”
:value=”item.id”
v-for=”item in xxx”
:key=”item.id”
>
</el-option>
</el-select>
<el-input
v-model=”numbers[index]”
:name=”‘name’ + index”
value=”0″
placeholder=”请输入”
>
</el-input>
</el-col>
<div class=”materials-but”>
<div class=”but” @click=”handleadd(item)”>+</div>
<div class=”but” @click=”handledel(item)”>-</div>
</div>
</div>
</el-form-item>
定义数据 :
values: “”,
numbers: “”,
controlNumber:[1,2]
created() {
this.values = Array(this.controlNumber.length).fill();
this.numbers = Array(this.controlNumber.length).fill();
},