首先增加全選按鈕:
<el-select filterable v-model="cityIds" multiple collapse-tags placeholder="請選擇" @change="getCityNames" > <el-option label="----全選----" value="000"></el-option> <el-option v-for="item in options.cityList" :key="item.area_id" :label="item.area_name" :value="item.area_id"> </el-option> </el-select>
通過watch事件進行,全選互斥:
watch: {
cityIds:function(value){
let valength = value.length;
if(valength > 1 && value[valength - 1] == "000"){
this.cityIds = ["000"];
}else if(valength == 2 && value[0] == "000"){
this.cityIds.shift();
}
}
},
最后再通過change事件進行數據處理,ok