js实现数据列表上下移动

//循环中的代码片段
<div @click="shopList == false ? tempSerial(productList, index) : ''">

       <icon iconClass="arrow-up" :class="temp == index && shopList == false ? 'actives' : 'arrow-up'" ></icon>

</div>

<div @click="shopList == false ? downtempSerial(productList, index) : ''">

       <icon iconClass="arrow-down" :class="temp2 == index && shopList == false ? 'actives' : 'arrow-down'" ></icon>

</div>





 tempSerial(item, index) { //向上移动  item是一个数组,index是当前的索引值

      this.temp = index

      this.temp2 = null

      if (index != 0) {

        item[index] = item.splice(index - 1, 1, item[index])[0]

      } else {

        item.push(item.shift())

      }

    },

    downtempSerial(item, index) {//向下移动  item是一个数组,index是当前的索引值

      this.temp = null

      this.temp2 = index

      if (index != item.length - 1) {

        item[index] = item.splice(index + 1, 1, item[index])[0]

      } else {

        item.unshift(item.splice(index, 1)[0])

      }

    },


版权声明:本文为chj_2020原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。