vue Draggable实现拖动改变顺序

  1. npm install vuedraggable

  2. import draggable from 'vuedraggable'

  3. 示例代码

Test.vue

<template>
 <ul class="sort-ul">
    <div>45454</div>
    <draggable  group="article" :value="sortArr" @input="handleListChange($event)">
       <li v-for="(item,index) in sortArr" :key="index">
         <h2>{{item.title}}</h2>
       </li>
    </draggable>
  </ul>
</template>
<script>
import Draggable from 'vuedraggable';

export default {
  name: 'Test',
  props:{
  },
  data () {
    return {
      fileList: [],
      sortArr:[
        {title:"00"},
        {title:"01"},
        {title:"02"},
        {title:"03"},
        {title:"04"},
        {title:"05"},
        {title:"06"},
        {title:"07"},
        {title:"08"},
        {title:"09"},
      ],
    }
  },
  components: {
    Draggable,  
  },
  methods: {
      // 更新位置
      handleListChange(event){
        console.log(event);
        this.sortArr = event;
      }
  },
  mounted () {
   
  }
}
</script>
<style>
  ul{
    padding: 0;
    width: 400px;
  }

  li{
    width: 100px;
    float:left;
  }

</style>

main.js

import Vue from 'vue'
import App from './App'
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
    el: '#app',
    components: { App },
    template: '<App/>'
})

app.vue

<template>
  <div id="app">
    <Test />
  </div>
</template>

<script>

import Test from '@/components/Test.vue'

export default {
  name: 'App',
  components:{
    Test,
  },
  methods: {
  }
}
</script>
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值