element多选框全选功能

<el-select v-model="mul" multiple placeholder="请选择" @change="labelChange">
   <el-checkbox v-model="allCheck" @change="selectAllLabel">全选</el-checkbox>
   <el-option label="1" :value="1"></el-option>
   <el-option label="2" :value="2"></el-option>
   <el-option label="3" :value="3"></el-option>
 </el-select>
<script>
export default {
	data () {
 		return {
 			mul: [],
	      	allMul: [1, 2, 3],
	      	allCheck: false
 		}
 	},
 	methods: {
		selectAllLabel () {
	      if (this.allCheck) {
	        this.mul = this.allMul
	      } else {
	        this.mul = []
	      }
	    },
	    labelChange (val) {
	      if (val.length === this.allMul.length) { 
	        this.allCheck = true
	      } else {
	        this.allCheck = false
	      }
	    }
    }
}
</script>

你可能感兴趣的:(element多选框全选功能)