Jua*_*dal 3 vue.js sortablejs vuedraggable multi-drag
最近我发现SortableJS / Vue.Draggable库(https://github.com/SortableJS/Vue.Draggable)有一个新选项,可以启用多拖动以从数组中选择多个元素并将它们移动到一起(https://github.com/SortableJS/Vue.Draggable/pull/744)。
我看过它完美运行的示例,例如:
但是当我尝试在我的项目中使用它时,我只能找到使它工作的方法。
以下是我的项目的详细信息:
在我的 vue 组件中,我以这种方式导入了 vuedraggable:
import draggable from 'vuedraggable'
Run Code Online (Sandbox Code Playgroud)
我已经应用了这种方式(为了这篇文章的目的,代码已经减少了):
<template>
<v-flex class="pa-3">
<div class="instructions-wrapper py-4">
<v-avatar size="40" color="#4C2159" class="white--text"><b>4</b></v-avatar>
<div class="px-2">
<h2>Revisa y asigna</h2>
<p>Revisa la optimización del sistema y asigna o personaliza una ruta</p>
</div>
</div>
<template v-for="(vehicle, key) in sortedRoutes.routes">
<v-card class="my-4" :key="vehicle.stops.location_id">
<v-toolbar color="primary" dark>
<v-toolbar-title>{{ Object.keys(sortedRoutes.routes).find(key => sortedRoutes.routes[key] === vehicle) }}</v-toolbar-title>
</v-toolbar>
<draggable
:key="vehicle.stops.location_id"
:list="vehicle.stops"
:id="key"
group="vehicle"
animation="150"
:multi-drag="true"
selected-class="multi-drag"
ghost-class="ghost"
:move="moveChecker"
@start="dragStart"
@end="dragEnd"
>
<div v-for="(delivery, index) in vehicle.stops" :key="delivery.id" class="draggable-element">
<v-list v-if="delivery.location_name !== 'CEDIS'" :key="delivery.title">
<v-list-tile>
<v-icon>drag_indicator</v-icon>
<v-list-tile-avatar>
<img :src="`https://ui-avatars.com/api/?color=fff&background=4C2159&size=128&name=${index}`">
</v-list-tile-avatar>
<v-list-tile-content>
<div>{{delivery.location_name}} {{deliveries.find(key => key.location.company_name === delivery.location_name).start_time_window ? `(${deliveries.find(key => key.location.company_name === delivery.location_name).start_time_window} - ${deliveries.find(key => key.location.company_name === delivery.location_name).end_time_window})` : ''}}
</div>
</v-list-tile-content>
</v-list-tile>
</v-list>
</div>
</draggable>
</v-card>
</template>
</v-flex>
</template>
Run Code Online (Sandbox Code Playgroud)
我已经注意到select-class通过 SortableJS / Vue.Draggable 文档添加了使用多拖动选项所需的属性。
作为可拖动列表打印的对象位于此 JSON 结构下:
{
"routes": {
"vehicle_1": {
"stops": [
{
"stop_id": 0,
"order_id": 1,
"location_id": "DEPOT",
"location_name": "Centro de distribución",
"lat": -100,
"lng": 100,
"arrival_time": "08:00",
"departure_time": "16:00"
},
{
"stop_id": 1,
"order_id": 2,
"location_id": "order_2",
"location_name": "Foo Zaas",
"lat": -100,
"lng": 100,
"arrival_time": "10:00",
"departure_time": "10:15"
}
],
"cost_matrix": [
[
{
"distance_in_meters": 10,
"travel_time_in_minutes": 10
},
{
"distance_in_meters": 100,
"travel_time_in_minutes": 100
}
],
[
{
"distance_in_meters": 10,
"travel_time_in_minutes": 10
},
{
"distance_in_meters": 100,
"travel_time_in_minutes": 100
}
]
],
"summary": {
"depot_name": "DEPOT",
"demand_assigned": 234,
"distance_in_meters": 3004,
"travel_time_in_minutes": 157,
"waiting_time_in_minutes": 70.1
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
尽管做了所有这些努力,我还是无法让它发挥作用。我什至必须复制一个更精简的代码版本,该版本基于我之前找到的一个代码笔并且它可以工作(https://codepen.io/Juan-Sin-Miedos/pen/jOWOyWW)
为什么它不适用于我的项目?
任何帮助将不胜感激,非常感谢!
小智 5
因为这个 pull request 没有合并,而且最新版本很旧,你需要从 git 安装这个版本。这是您应该放入 package.json 而不是版本号的内容:
"vuedraggable": "git://github.com/divinespear/Vue.Draggable.git#multi-drag"
| 归档时间: |
|
| 查看次数: |
2711 次 |
| 最近记录: |