js数组实现上移下移

Posted WMY

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js数组实现上移下移相关的知识,希望对你有一定的参考价值。

up(index) {
            if(index === 0) {
              return
            }
            //在上一项插入该项
            this.list.splice(index - 1, 0, (this.list[index]))
            //删除后一项
            this.list.splice(index + 1, 1)

            this.save();
        },
        down(index) {
            if (index === (this.list.length-1)) {
              return
            }
            // 在下一项插入该项
            this.list.splice(index + 2, 0, (this.list[index]))
            // 删除前一项
            this.list.splice(index, 1)

            this.save();
        },

 

以上是关于js数组实现上移下移的主要内容,如果未能解决你的问题,请参考以下文章