关于上移下移,一行代码完成数据交换

      onMoveUp (index) {
          if (index !== 0) {
          this.swapArray(this.dataList, index, index - 1)
        } else {
          this.$message({message: '已经处于置顶,无法上移', type: 'warning'})
        }
      },
      onMoveDown (index) {
        let len = this.dataList.length
        if (index + 1 !== len) {
          this.swapArray(this.dataList, index, index + 1)
        } else {
          this.$message({message: '已经处于置底,无法下移', type: 'warning'})
        }
      },
      swapArray (arr, indexOne, indexTwo) {
        arr[indexOne] = arr.splice(indexTwo, 1, arr[indexOne])[0]
        return arr
      }

猜你喜欢

转载自blog.csdn.net/WDCCSDN/article/details/84794929