Draggable為基於Sortable.js的vue組件,用以實現拖拽功能。
特性
支持觸摸設備
支持拖拽和選擇文本
支持智能滾動
支持不同列表之間的拖拽
不以jQuery為基礎
和視圖模型同步刷新
和vue2的國度動畫兼容
支持撤銷操作
當需要完全控制時,可以拋出所有變化
可以和現有的UI組件兼容
安裝
npm install vuedraggable
引入
import draggable from 'vuedraggable'
官方例子:
hello.vue
<template> <div class="fluid container"> <div class="form-group form-group-lg panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">Sortable control</h3> </div> <div class="panel-body"> <div class="checkbox"> <label><input type="checkbox" v-model="editable">Enable drag and drop</label> </div> <button type="button" class="btn btn-default" @click="orderList">Sort by original order</button> </div> </div> <div class="col-md-3"> <draggable class="list-group" element="ul" v-model="list" :options="dragOptions" :move="onMove" @start="isDragging=true" @end="isDragging=false"> <transition-group type="transition" :name="'flip-list'"> <li class="list-group-item" v-for="element in list" :key="element.order"> <i :class="element.fixed? 'fa fa-anchor' : 'glyphicon glyphicon-pushpin'" @click=" element.fixed=! element.fixed" aria-hidden="true"></i> {{element.name}} <span class="badge">{{element.order}}</span> </li>