上移:
table 里列的 template里按钮
<el-button size="mini" type="text" @click="handleUp(scope.$index, scope.row)">上移</el-button>
<el-button size="mini" type="text" @click="handleDown(scope.$index, scope.row)">下移</el-button>
methods: {
handleUp (index, row) { // 上移
const len = this.tableData[index - 1]
this.$set(this.tableData, index - 1, this.tableData[index])
this.$set(this.tableData, index, len)
},
handleDown (index, row) { // 下移
const len = this.tableData[index + 1]
this.$set(this.tableData, index + 1, this.tableData[index])
this.$set(this.tableData, index, len)
}
}
使用$set 可更新视图
本文介绍如何在Vue中使用Element UI的table组件实现列表项的上移和下移功能,通过自定义模板内的按钮触发事件,利用Vue的$set方法确保数据变化实时更新到视图。
1670

被折叠的 条评论
为什么被折叠?



