VUE中获取TABLE的SELECTION选中的数据

  • Post author:
  • Post category:vue


table绑定一列type为selection,绑定table中的@selection-change=“selectionLineChangeHandle”,每次点击触发事件,赋值给数组,最后提交时候遍历获取需要的值

table绑定@selection-change事件

  <el-table 
      :data="dataonLineList"
      border
      @selection-change="selectionLineChangeHandle"
      style="width: 100%;">
  • table中定义一列type为selection

 <el-table-column
        type="selection"
      width="55">
      </el-table-column>
  • return中定义数组

 dataonLineListSelections: [],

methods中添加事件

selectionLineChangeHandle (val) {
       this.dataonLineListSelections = val
},

提交时遍历列表,获取对应的数据id是你表格里面绑定的列

//提交
fromCommit  () {
   console.log(this.dataonLineListSelections);
   for(var i = 0; i< this.dataonLineListSelections.length; i++){
         console.log('id:'+this.dataonLineListSelections[i].id)
       }
 }