可拖拽排序的vue组件

最近在优化一个vue的博客系统,想实现文章列表处的文章拖拽功能。就试了一下awe-dnd vue插件,觉得还挺好用的。

安装
npm install awe-dnd --save
使用

在main.js中,通过Vue.use引入

import VueDND from 'awe-dnd'
Vue.use(VueDND)

在vue文件中的使用

<template>
  <div class="color-list"> <div class="color-item" v-for="color in colors" v-dragging="{ item: color, list: colors, group: 'color', otherData: otherData }" :key="color.text" >{{color.text}}</div> </div> </template> <script> export default { data () { return { colors: [{ text: "Aquamarine" }, { text: "Hotpink" }, { text: "Gold" }, { text: "Crimson" }, { text: "Blueviolet" }, { text: "Lightblue" }, { text: "Cornflowerblue" }, { text: "Skyblue" }, { text: "Burlywood" }] } }, mounted () { this.$dragging.$on('dragged', ({ value }) => { console.log(value.item) console.log(value.list) console.log(value.otherData) }) this.$dragging.$on('dragend', () => { }) } } </script> 
组件参数
名称类型默认值说明
itemObject-每一个可拖拽的对象
listArray-可拖拽对象的数组
groupString-这是一个dragging list的unique key

拖拽完成之后,需要把新的数组顺序提交到后台,创建一个sort_order字段保存顺序。

参考: 可拖动排序的vue组件 , github



作者:real_ting
链接:https://www.jianshu.com/p/7afcf8a7af75
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

转载于:https://www.cnblogs.com/Jeely/p/11231477.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值