[英]how to enable only one way drag in 2 lists draggable in vuejs
I am using vuedraggable library to create draggable items( https://github.com/SortableJS/Vue.Draggable )我正在使用 vuedraggable 库来创建可拖动的项目( https://github.com/SortableJS/Vue.Draggable )
I want to create two draggable lists and I only enable drag from list1 to list2.我想创建两个可拖动列表,并且我只启用从 list1 到 list2 的拖动。 So I want to disable drag from list2 to list1 and list2 is empty.所以我想禁用从 list2 到 list1 的拖动并且 list2 是空的。 So I only want to move from list1 to list2.所以我只想从 list1 移动到 list2。 I found an example for two lists draggable you can see below:我找到了两个可拖动列表的示例,您可以在下面看到:
<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>
You can see the example here also: https://sortablejs.github.io/Vue.Draggable/#/two-lists你也可以在这里看到这个例子: https://sortablejs.github.io/Vue.Draggable/#/two-lists
The move
prop might be what you're looking for and you can use it in the second list as follows: move
道具可能是您要找的东西,您可以在第二个列表中使用它,如下所示:
<draggable class="list-group" :list="list2" group="people" @change="log"
:move="checkMove" // <--- add this one
>
// in script
methods: {
checkMove() {
return false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.