Bootstrap

el-select 列表全选多选

<template>
  <div>
    <el-select
      multiple
      placeholder="请选择"
      v-model="value"
      @change="change"
      collapse-tags
    >
      <el-option key="全选" label="全选" value="全选"> </el-option>

      <el-option
        v-for="(item, key) in list"
        :key="key"
        :label="item"
        :value="item"
      >
      </el-option>
    </el-select>
  </div>
</template>


<script>
export default {
  data() {
    return {
      value: [],
      list: [
        // { id: 1, name: "全部" },
        // { name: "未生效" },
        // { name: "已生效" },
        // { name: "生效中" },
        "未生效",
        "已生效",
        "生效中",
      ],
      all: false,
    };
  },
  methods: {
    change(val) {
      if (this.all) {
        this.all = false;
        if (val.indexOf("全选") > -1) {
          this.value = val.filter((p) => p != "全选");
        } else {
          this.value = [];
        }
      } else {
        if (val.indexOf("全选") > -1) {
          this.value = ["全选", ...this.list];
          this.all = true;
        } else {
          if (val.length === this.list.length) {
            this.value = ["全选", ...this.list];
            this.all = true;
          } else {
            this.value = val;
          }
        }
      }
      console.log(this.value);
    },
  },
};
</script>

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;