【问题标题】:Sortable not working in el-table-column with checkbox可排序在带有复选框的 el-table-column 中不起作用
【发布时间】:2019-11-13 10:46:30
【问题描述】:

当我尝试使用第一列或第二列进行排序时,除了最后一列中的复选框外,所有行都会被排序。根据我的代码,最后一列是否不相交?

<el-table :data="items" stripe style="width: 50%">
                <el-table-column prop="email" label="email" sortable></el-table-column>
                <el-table-column prop="username" label="Username" sortable></el-table-column>
                <el-table-column label="Enable">
                    <template slot-scope="scope">
                        <el-checkbox :checked="scope.row.isSelected" @change="toggleEnable(scope.row)"  />
                    </template>
                </el-table-column>
            </el-table>

【问题讨论】:

    标签: vue.js element-ui


    【解决方案1】:

    所以基本上 DOM 没有改变,所以 Vue 无法识别变化。为了给 Vue 一个提示以便它可以跟踪每个节点的身份,从而重用和重新排序现有元素,您需要为每个项目提供一个唯一的 key 属性。如果是元素 ui 表,您应该填写 row-key 属性。列在table-atributes

    添加row-key 将解决您的挑战

    使其工作的另一种方法是将:checked 替换为v-model。但还是提供row-key

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-08
      相关资源
      最近更新 更多