html部分
<el-select v-model="ruleForm.staff_attendance_name" clearable multiple placeholder="请选择" @change="selectAll" @remove-tag="removeTag">
<el-option label="全选" value="全选" ></el-option>
<el-option v-if="ruleForm.staff_attendance_name!=['全选']" v-for="item in attendanceTeamInfo" :key="item.name" :label="item.name"
:value="item.name">
</el-option>
</el-select>
js部分
//考勤地点点击全选
selectAll(val) {
var inx=val.findIndex(item=>item=='全选');
if(this.allCheck&&inx>-1){ //如果是全选,并且剩余的数组里有全选,就把全选删了
if(inx>-1){
val.splice(inx,1)
}
this.allCheck=false;
}else{
if(inx>-1){
this.allCheck=true;
var arr=['全选'];
this.attendanceTeamInfo.forEach(ele=>{
arr.push(ele.name);
this.ruleForm.staff_attendance_name=arr;
})
}else if(val.length==this.attendanceTeamInfo.length&&this.allCheck){
this.ruleForm.staff_attendance_name=[];
this.allCheck=false;
}else if(val.length==this.attendanceTeamInfo.length){
this.allCheck=true;
this.ruleForm.staff_attendance_name.unshift('全选')
}
}
},
//移除全选时,清空选项
removeTag(val){
if(val=='全选'){
this.ruleForm.staff_attendance_name=[]
}
},
真好呢
真好呢