最近要作拖拽相關的功能,原本想本身寫,突然想起來以前在輪子工廠有更新過,vue-dragging仍是很好用滴。vue
vue-dragging -- 一款可任意拖動排序的vue插件。支持桌面和移動端,拖拽過渡動畫美觀。支持vue1和vue2版本。很是實用。npm
經過NPM安裝動畫
$ npm install awe-dnd --save
在main.js中,經過Vue.use導入插件網站
import VueDND from 'awe-dnd' Vue.use(VueDND)
在你的vue文件中這樣引用this
<script> export default { data () { return { colors: [{ text: "Aquamarine" }, { text: "Hotpink" }, { text: "Gold" }, { text: "Crimson" }, { text: "Blueviolet" }, { text: "Lightblue" }, { text: "Cornflowerblue" }, { text: "Skyblue" }, { text: "Burlywood" }] } } } </script> <template> <div class="color-list"> <div class="color-item" v-for="color in colors" v-dragging="{ item: color, list: colors, group: 'color' }" :key="color.text" >{{color.text}}</div> </div> </template>
vue2.0的使用方式url
<div class="color-list"> <div class="color-item" v-for="color in colors" v-dragging="{ item: color, list: colors, group: 'color' }" :key="color.text" >{{color.text}}</div> </div>
vue1.0的使用方式插件
<div class="color-list"> <div class="color-item" v-for="color in colors" v-dragging="{ item: color, list: colors, group: 'color', key: color.text }" track-by="text" >{{color.text}}</div> </div>
添加事件code
<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>
export default { mounted () { this.$dragging.$on('dragged', ({ value }) => { console.log(value.item) console.log(value.list) console.log(value.otherData) }) this.$dragging.$on('dragend', () => { }) } }
輪子工廠--一個分享vue,angular優秀組件的網站排序