刘磊
2025-04-19 2f18780a16a68f7fc67dd3bca61b8d0aed7c8e1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
let methods = {
  add() {
    this.$Message.success('点击了添加按钮')
  },
  edit() {
    let rows = this.getSelected()
    if (rows.length == 0) {
      return this.$Message.error('请选择要编辑的行!')
    }
    this.$Message.success('点击了编辑按钮')
  },
  del() {
    let rows = this.getSelected()
    if (rows.length == 0) {
      return this.$Message.error('请选择要删除的行!')
    }
    this.$Message.success('点击了删除按钮')
  },
  getSelected() {
    return this.selectRows
  },
 
  selectionChange(selection) {
    // console.log(selection);
    // 选择行事件,只有单选才触发
    this.selectRows = selection
    if (this.single) {
      if (selection.length == 1) {
        this.$emit('rowChange', selection[0])
      }
      if (selection.length > 1) {
        let _row = selection[selection.length - 1]
        this.$refs.table.toggleRowSelection(selection[0])
        this.selectRows = [_row]
      }
    }
    // 将selectionchange暴露出去
    this.$emit('selectionChange', selection)
  }
}
export default {
  methods
}