zoukankan      html  css  js  c++  java
  • vue使用sortable实现拖拽排序

    下载:
    npm install sortablejs --save

    引入:
    import Sortable from ‘sortablejs’

    <template>
      <div class="flex" id="items">
        <div class="item" v-for="(item,index) in value">
          <p>{{item.name}}</p>
        </div>
      </div>
    </template>
    <style scope>
      .item{
        100px;
        height: 100px;
        border: solid 1px #ccc;
        font-size: 16px;
      }
      .flex{
        display: flex;
        justify-content: space-around;
      }
    </style>

    <script>
    import Sortable from 'sortablejs'
    export default {
      name: 'operationsAdd',
      data () {
        return {
          value: [
            { name: 11111 },
            { name: 22222 },
            { name: 33333 },
            { name: 44444 }
          ]
        }
      },
      methods: {
        test() {
          var that = this
          var el = document.getElementById('items')
          // 常用
          new Sortable(el, {
            onEnd: function (evt) {
             // 获取排序之后的data数据
              that.value.splice(evt.newIndex, 0, that.value.splice(evt.oldIndex, 1)[0])
              var newArray = that.value.slice(0)
              that.value = []
              that.$nextTick(function () {
                that.value = newArray
                console.log(that.value)
              })
            }
          })
        }
      },
      mounted () {
        this.test()
      }
    }
    </script>

  • 相关阅读:
    linux下FTP设置技巧
    STM32开发板基础教程(七) ADC with DMA
    linux FTP配置详解
    _crol_小解
    浅谈STM32的DMA模块的使用
    STM32学习笔记(12)DMA初步
    C51中的INTRINS.H:内部函数
    STM32 DMA控制器使用
    KEILC51编译问题ERROR L104: MULTIPLE PUBLIC DEFINITIONS重复定义
    STM32的DMA演示,USART
  • 原文地址:https://www.cnblogs.com/zjxiang008/p/15075382.html
Copyright © 2011-2022 走看看