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