1:HTML
// :disabled="item.disabled"
<el-select v-model="value" placeholder="请选择" @change="change" @focus="getOptions">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
:disabled="item.disabled">
</el-option>
</el-select>
2:js
data里声明一个(id_list)数组存储已经选中的id
data() {
return {
options:[]
id_list: []
}
},
//选中以后存储
change(value) {
that.firm_id_list.push(value)
}
getOptions() {
const that = this
that.$axios({
method: 'get',
url:''
}).then((res) => {
if (res.data.message === 'success') {
const { data } = res
// 这里获取的数组和存储的数组对比一下,如果一样就disabled = true反之为false
data.data.results.forEach(v => {
if (that.firm_id_list.includes(v.id)) {
v.disabled = true
} else {
v.disabled = false
}
})
that.options= res.data.data.results
}
})
},