vueElementUi-选择框选中之后翻页进行状态保持及默认选中

9次阅读

共计 972 个字符,预计需要花费 3 分钟才能阅读完成。

复选框

<el-table
:data="list"
ref="multipleTable"
:row-key="(row)=>{return row.classId}"
@selection-change="handleSelectionChange"
style="width: 100%">
<el-table-column type="selection" :reserve-selection="true" ></el-table-column>
</el-table>

// 切换分页持久化选中表格

:row-key="(row)=>{return row.classId}"
:reserve-selection="true"

//@selection-change 会返回所有选中的数据
//@select 会返回所有选中的数据及当前操作的数据

清空所有选中

this.$refs.multipleTable.clearSelection();// 页面中有搜索或重置时可能会用到。

默认选中

this.$refs.multipleTable.toggleRowSelection(this.list[index]);// 必须传表格的数据;以数组 [下标] 格式传递

单选框

<el-table
      :data="list"
      ref="multipleTable"
      :row-key="(row)=>{return row.classId}"
      @current-change="handleCurrentRadio"
      style="width: 100%">
      <el-table-column width="80" v-if="radioShow">
        <template slot-scope="scope">
          <el-radio v-model="radio"  :label="scope.row.classId">{{''}}</el-radio>
        </template>
              </el-table-column>
    </el-table>

//@current-change="handleCurrentRadio"会返回选中的数据。可以在这个事件用 return false 来阻止选中
//label 和原生的 value 属性一样。利用 v -model 来绑定唯一值,意味着 label 的值为唯一的。
//{{“”}}为了让单选框不显示 label。

正文完
 0