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>

  • 相关阅读:
    moment.js获取当前日期是当年的第几周
    angulajs中引用chart.js做报表,修改线条样式
    moment算本月开始日期和结束日期
    TFS(Team Foundation Server)敏捷使用教程(四):工作项跟踪(1)
    个人微信收款回调通知
    Winform,Wpf快捷键
    RemindMe
    数组循环左移p位
    RemindMe 说明
    双网卡同时上内外网
  • 原文地址:https://www.cnblogs.com/zjxiang008/p/15075382.html
Copyright © 2011-2022 走看看