ElementUI el-select includes all in the case of multiple selection, how does everyone achieve it? Do you write it yourself?

look for it on the official website, but there is no corresponding example and api

<template>
  <el-select class="g-public-multi-select" v-model="selectWeekDayListProp" :disabled="disabled" @change="selectChange" multiple>
    <el-option
      v-for="item in weekDayAry"
      :key="item.value"
      :label="item | getName"
      :value="item.value">
    </el-option>
  </el-select>
</template>
<style>
  .el-select__tags {
    max-width: 375px !important;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

</style>

<script>
  import _const from "@/utils/constants"

  export default {
    name: "weekDayMultipleSelect",
    props: ["selectWeekDayList", "disabled"],
    data() {
      return {
        selectWeekDayListProp: this.selectWeekDayList,
        isContainAll: true,
        weekDayAry:  [
          { "value": 0, "nameCn": "", "nameEn": "All" },
          { "value": 1, "nameCn": "", "nameEn": "Monday" },
          { "value": 2, "nameCn": "", "nameEn": "Tuesday" },
          { "value": 3, "nameCn": "", "nameEn": "Wednesday" },
          { "value": 4, "nameCn": "", "nameEn": "Thursday" },
          { "value": 5, "nameCn": "", "nameEn": "Friday" },
          { "value": 6, "nameCn": "", "nameEn": "Saturday" },
          { "value": 7, "nameCn": "", "nameEn": "Sunday" }
        ]
      }
    },
    filters:{
        getName(item) {
          if (item === null) return
          if (store.getters.lang === "zh") {
            return item.nameCn
          } else {
            return item.nameEn
          }
        }
    },
    methods: {
      // 
      selectChange() {
        // 
        if (this.isContainAll) {
          // 
          // 
          this.isContainAll = false
          // 
          this.selectWeekDayListProp.splice(0, 1)
        } else {
          // 
          // 
          this.isContainAll = this.selectWeekDayListProp.some(value => value === 0)
          // 
          if (this.isContainAll) {
            // value=0 
            this.selectWeekDayListProp = [0]
          } else {
            // 
            if (this.selectWeekDayListProp.length === 7) {
              // 
              this.selectWeekDayListProp = [0]
              this.isContainAll = true
            }
          }
        }
        // 
        if (this.selectWeekDayListProp.length === 0) {
          // 
          this.selectWeekDayListProp = [0]
          this.isContainAll = true
        }
        this.$emit("update:selectWeekDayList", this.selectWeekDayListProp)
        this.$emit("change")
      }
    }
  }
</script>

I wrote it myself


add a multi-check box to drop all values into the array and uncheck to clear the values.


<el-select v-model="selectWeekDayAryProp" @change="selectChange" multiple>
  <el-option
    v-for="item in weekDayAry"
    :key="item.value"
    :label="item.label"
    :value="item.value">
  </el-option>
</el-select>


data() {
  return {
    selectWeekDayAryProp: this.selectWeekDayAry,
    isSelectAll: false,
    weekDayAry: _const.weekDayAry
  }
},

 if (this.isSelectAll) {
  // 
  // 
  this.isSelectAll = false
  // 
  this.selectWeekDayAryProp.splice(0, 1)
} else {
  // 
  // 
  this.isSelectAll = this.selectWeekDayAryProp.some(value => value === 0)
  // 
  if (this.isSelectAll) {
    // value=0 
    this.selectWeekDayAryProp = [0]
  } else {
    // 
    if (this.selectWeekDayAryProp.length === 7) {
      // 
      this.selectWeekDayAryProp = [0]
      this.isSelectAll = true
    }
  }
}

}


Hello, could you paste the code a little bit? I also want to do this function, but according to your code here, I did not succeed in the test, thank you!


Hello, when I use your method to implement it, if I select all first, and then select other options, it will still be the result of all selection. How should this be solved

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bddffa-313cc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bddffa-313cc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?