el-select --->全选功能


<template>
  <el-select v-model="value" placeholder="请选择"
    reserve-keyword
    :filter-method="filterFun">
    <el-option
     :class="'allSelected' ? allSelected && index === 0"
      v-for="(item, index) in options"
      @click.native=handleOptionClick(index)
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
</template>

<script>
  export default {
    data() {
      return {
        value: '',
        allSelected: false,
        option:[],
        optionCopy:[]
      }
    },
    methods:{
     handleOptionClick(index){
      if(index === 0){
          this.allSelected = !this.allSelected
          this.value = this.allSelected ? this.option.slice(1).map(item => item.value) : []
       }
       this.allSelected  = (this.value.length === this.option.length -1)
      }
    },
    filterFun (val) {
     this.option = this.optionCopy.filter(item=> {
      if(item.labe.indexOf(val) !== -1){
       return item
       }
     })
      this.option.unshift({value: '',label: '全选'})
    }
  }
</script>        

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM