@change="(value) => selected(value, item)"
selected(val, item) {
if (val === true) {
this.selectedData.push(item.courseware_id)
} else {
let index = this.selectedData.indexOf(item.courseware_id);
if (index > -1) {
this.selectedData.splice(index, 1);
}
}
},
//组件
<el-select v-model="oil" @change="selected" placeholder="请选择">
<el-option
v-for="item in treeList"
:key="item.id"
:label="item.name"
:value="item.id"
>
</el-option>
</el-select>
//js
selected(val) {
let data = this.treeList.find(item => {
if (item.id === val) {
return item
}
});
console.log(data);
},
重点:根据值查数组相同的元素