我正在使用vuedraggable库来创建可拖动项(https://github.com/SortableJS/Vue.Draggable)
我想创建两个可拖动的列表,并且我只允许从列表1拖动到列表2。所以我想禁用从列表2拖动到列表1,并且列表2为空。所以我只想从列表1移到列表2。我发现了两个可拖动列表的示例,您可以在下面看到:
<template>
<div class="row">
<div class="col-3">
<h3>Draggable 1</h3>
<draggable class="list-group" :list="list1" group="people" @change="log">
<div
class="list-group-item"
v-for="(element, index) in list1"
:key="element.name"
>
{{ element.name }} {{ index }}
</div>
</draggable>
</div>
<div class="col-3">
<h3>Draggable 2</h3>
<draggable class="list-group" :list="list2" group="people" @change="log">
<div
class="list-group-item"
v-for="(element, index) in list2"
:key="element.name"
>
{{ element.name }} {{ index }}
</div>
</draggable>
</div>
<rawDisplayer class="col-3" :value="list1" title="List 1" />
<rawDisplayer class="col-3" :value="list2" title="List 2" />
</div>
</template>
<script>
import draggable from "@/vuedraggable";
export default {
name: "two-lists",
display: "Two Lists",
order: 1,
components: {
draggable
},
data() {
return {
list1: [
{ name: "John", id: 1 },
{ name: "Joao", id: 2 },
{ name: "Jean", id: 3 },
{ name: "Gerard", id: 4 }
],
list2: []
};
},
methods: {
add: function() {
this.list.push({ name: "Juan" });
},
replace: function() {
this.list = [{ name: "Edgard" }];
},
clone: function(el) {
return {
name: el.name + " cloned"
};
},
log: function(evt) {
window.console.log(evt);
}
}
};
</script>
您也可以在这里看到示例:https://sortablejs.github.io/Vue.Draggable/#/two-列出
move
道具可能是您想要的,您可以在第二个列表中使用它,如下所示:
<draggable class="list-group" :list="list2" group="people" @change="log"
:move="checkMove" // <--- add this one
>
// in script
methods: {
checkMove() {
return false;
}
}