放张图:
Vue文件:
<el-table-column property="address" label="顺序" width="120" align='center'> <template slot-scope="scope"> <!-- <a class="dialogIcon4_5" @click="upMoveBtn(scope)"></a> <a class="dialogIcon4_2" @click="downMoveBtn(scope)"></a> --> <a class="dialogIcon4_5" @click="changeIndex(scope.row.index,-1)"></a> <a class="dialogIcon4_2" @click="changeIndex(scope.row.index,1)"></a> </template> </el-table-column>
<el-table :row-class-name="tableRowClassName" stripe :data="gridData" max-height="400" :row-style="{height: '20px'}" :cell-style="{padding:'5px'}">
Js文件:
changeIndex(index,change){ if((index+change)>=0&&((index+change)<=this.gridData.length)){ let item=this.gridData.splice(index,1)[0]; this.gridData.splice(index+change,0,item); } console.log('this.gridData: ', this.gridData); //[this.gridData[index],this.gridData[index-1]] = [this.gridData[index-1],this.gridData[index]]; }, tableRowClassName({row, rowIndex}){ row.index=rowIndex; },PS:参考自网上:https://www.jb51.net/article/181440.htm 但是原文那个let item=this.gridData.splice(index,1)[0];应该放在if判断里面,不然每次点击上移或下移数组会删除掉元素。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。