vue+elementUI实现全选功能

vue+elementUI实现全选功能_第1张图片
需要实现这样的功能,全选和判断是否是全选状态.因为样式的需要所以结构和elementUI案例结构有点区别

全选 {{item.name}} {{item.phone}}

这个地方是模拟的数据

export default {
  data() {
    return {
      isIndeterminate: false,
      checkAll: false,
      check: [],
      checkedGameId: [],
      checkedList: [
        {
          id: 1,
          name: "张三",
          phone: "13554006475"
        },
        {
          id: 2,
          name: "李四",
          phone: "13514002475"
        },
        {
          id: 3,
          name: "王五",
          phone: "13558992475"
        }
      ]
    };
  },

这个地方是定义的方法

methods: {
    init() {
      for (let i = 0; i < this.checkedList.length; i++) {
        this.checkedGameId.push(this.checkedList[i].id);
      }
    },
    handleCheckAllChange(val) {
      this.check = val ? this.checkedGameId : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.checkedList.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.checkedList.length;
    }
  },
  created() {
    this.init();
  }

有帮助的可以在下方留言

你可能感兴趣的:(vue+elementUI实现全选功能)