当前位置:   article > 正文

el-select 列表全选多选_el-select多选全选

el-select多选全选
  1. <template>
  2. <div>
  3. <el-select
  4. multiple
  5. placeholder="请选择"
  6. v-model="value"
  7. @change="change"
  8. collapse-tags
  9. >
  10. <el-option key="全选" label="全选" value="全选"> </el-option>
  11. <el-option
  12. v-for="(item, key) in list"
  13. :key="key"
  14. :label="item"
  15. :value="item"
  16. >
  17. </el-option>
  18. </el-select>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. value: [],
  26. list: [
  27. // { id: 1, name: "全部" },
  28. // { name: "未生效" },
  29. // { name: "已生效" },
  30. // { name: "生效中" },
  31. "未生效",
  32. "已生效",
  33. "生效中",
  34. ],
  35. all: false,
  36. };
  37. },
  38. methods: {
  39. change(val) {
  40. if (this.all) {
  41. this.all = false;
  42. if (val.indexOf("全选") > -1) {
  43. this.value = val.filter((p) => p != "全选");
  44. } else {
  45. this.value = [];
  46. }
  47. } else {
  48. if (val.indexOf("全选") > -1) {
  49. this.value = ["全选", ...this.list];
  50. this.all = true;
  51. } else {
  52. if (val.length === this.list.length) {
  53. this.value = ["全选", ...this.list];
  54. this.all = true;
  55. } else {
  56. this.value = val;
  57. }
  58. }
  59. }
  60. console.log(this.value);
  61. },
  62. },
  63. };
  64. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/107262?site
推荐阅读