<div style="display: flex; align-items: flex-end">
<div>
<div
v-for="(itemValue, index) in obj.addProductInfo.basisValue"
:key="index"
class="item"
>
<el-select
:ref="'selectRef'+itemValue.code"
filterable
v-model="itemValue.code"
placeholder="请选择"
@change="(e) =>standardsChange(e,itemValue,num,obj.addProductInfo.basisValue)"
style="width: 380px"
>
<div v-for="(item, index) in projectParams" :key="index">
<el-option
:label="item.label"
:value="item.value"
:disabled="item.disabled"
></el-option>
</div>
</el-select>
</div>
</div>
<div>
<el-button
type="primary"
@click="addFn"
style="margin-left: 16px"
>+ 添加</el-button
>
</div>
</div>
//新增方法
addFn(arr) {
this.getChoiceArr(arr)
this.tabsOptions.map((v) => {
console.log(v, "v");
if (v.value == this.activeName) {
v.addProductInfo.basisValue.push({
code: "",
name:''
});
}
});
//下拉框change事件
standardsChange(e,obj,num,arr) {
//obj新增的每一项的对象
//arr就是存放所有新增的数据
this.getChoiceArr(obj,num,arr)
},
//抽离的方法
getChoiceArr(row,num,arr) {
var idx = -1;
this.projectParams.forEach((t,index) => {
arr.forEach(item => {
if (item.code == t.value) {
t.disabled = true;
idx = index
}
})
if (idx != index) {
t.disabled = false;
}
});
},
参考文档:https://blog.youkuaiyun.com/xiaojuju0/article/details/129825775