欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vuedraggable实现列表拖动排序

程序员文章站 2022-04-25 16:50:09
...

vuedraggable实现列表拖动排序
文档地址

安装

npm i -S vuedraggable

页面进行导入

import draggable from "vuedraggable";

完整代码效果

<template>
  <div class="box">
    <draggable v-model="list" chosenClass="active" animation="500" @end="dragEnd">
      <div class="row" v-for="(item,index) in list" :key="index">{{item}}</div>
    </draggable>
  </div>
</template>

<script>
import draggable from "vuedraggable";
export default {
  components: {
    draggable
  },
  data() {
    return {
      list: [1, 2, 3, 4, 5, 6, 7]
    };
  },
  methods: {
    dragEnd() {
      console.log(this.list);
    }
  }
};
</script>

<style scoped>
.row {
  background: cadetblue;
  width: 100%;
  height: 150px;
  line-height: 150px;
  text-align: center;
  margin: 15px 0;
}
.active {
  background: chocolate !important;
}
</style>
相关标签: Module