如何使用 Vue draggable 将项目从组件中的列表拖动到另一个组件中的列表?
How can I drag items from list in component to list inside another component using Vue draggable?
我正在尝试使用 vue draggable 将项目从一个列表移动到另一个列表,但是列表在组件内部,我无法让它工作。这些项目可以在列表内移动,但不能从列表移动到另一个列表。
我有一个包含所有列表的 Board 组件和一个包含可拖动项目的 List 组件。
这是电路板组件:
<template>
<div class="board">
<BoardMenu :users="this.users" :name="this.name"> </BoardMenu>
<div class="boardContent">
<Backlog></Backlog>
<div class="lists">
<List
class="list"
v-for="list in lists"
:key="list.id"
:id="list.id"
:items="list.items"
></List>
</div>
</div>
</div>
</template>
<script>
import BoardMenu from "./BoardMenu";
import Backlog from "./Backlog";
import List from "./List";
export default {
name: "UserIcon",
props: {
id: Number
},
components: {
BoardMenu,
Backlog,
List
},
data() {
return {
name: "BOARDNAME",
users: [{ name: "Bram Coenders" }, { name: "Jasper van der Zwaan" }],
lists: [
{
id: 1,
items: [
{
type: "story",
id: 1,
listId: 1
},
{
id: 2,
listId: 1
},
]
},
{ id: 2, items: [] }
],
backlog: { id: 2 }
};
},
};
</script>
这是列表组件:
<template>
<div class="list">
<div class="list-header">
<h2 id="list-name">{{ name }}</h2>
<p id="list-description">{{ description }}</p>
</div>
<draggable
v-model="items"
:list="this.id"
class="list-list"
>
<div :id="item.id" class="list-item" v-for="item in items" :key="item.id">
<div v-if="item.type == 'story'">
<Story class="story" :id="item.id"></Story>
</div>
<div v-else>
<Task class="task" :id="item.id"></Task>
</div>
</div>
</draggable>
</div>
</template>
<script>
import draggable from "vuedraggable";
import Story from "./Story.vue";
import Task from "./Task.vue";
export default {
name: "List",
components: {
Story,
Task,
draggable
},
props: {
items: []
},
data() {
return {
name: "To do",
description: "this sprint."
};
},
methods :{
newItem: function(){
console.log("test")
}
}
};
</script>
将 :options='{group: "items"}'
添加到您的可拖动组件,或者您可以尝试添加属性 group="items"
(如果您使用的是 Vue 2.2+)
我正在尝试使用 vue draggable 将项目从一个列表移动到另一个列表,但是列表在组件内部,我无法让它工作。这些项目可以在列表内移动,但不能从列表移动到另一个列表。
我有一个包含所有列表的 Board 组件和一个包含可拖动项目的 List 组件。
这是电路板组件:
<template>
<div class="board">
<BoardMenu :users="this.users" :name="this.name"> </BoardMenu>
<div class="boardContent">
<Backlog></Backlog>
<div class="lists">
<List
class="list"
v-for="list in lists"
:key="list.id"
:id="list.id"
:items="list.items"
></List>
</div>
</div>
</div>
</template>
<script>
import BoardMenu from "./BoardMenu";
import Backlog from "./Backlog";
import List from "./List";
export default {
name: "UserIcon",
props: {
id: Number
},
components: {
BoardMenu,
Backlog,
List
},
data() {
return {
name: "BOARDNAME",
users: [{ name: "Bram Coenders" }, { name: "Jasper van der Zwaan" }],
lists: [
{
id: 1,
items: [
{
type: "story",
id: 1,
listId: 1
},
{
id: 2,
listId: 1
},
]
},
{ id: 2, items: [] }
],
backlog: { id: 2 }
};
},
};
</script>
这是列表组件:
<template>
<div class="list">
<div class="list-header">
<h2 id="list-name">{{ name }}</h2>
<p id="list-description">{{ description }}</p>
</div>
<draggable
v-model="items"
:list="this.id"
class="list-list"
>
<div :id="item.id" class="list-item" v-for="item in items" :key="item.id">
<div v-if="item.type == 'story'">
<Story class="story" :id="item.id"></Story>
</div>
<div v-else>
<Task class="task" :id="item.id"></Task>
</div>
</div>
</draggable>
</div>
</template>
<script>
import draggable from "vuedraggable";
import Story from "./Story.vue";
import Task from "./Task.vue";
export default {
name: "List",
components: {
Story,
Task,
draggable
},
props: {
items: []
},
data() {
return {
name: "To do",
description: "this sprint."
};
},
methods :{
newItem: function(){
console.log("test")
}
}
};
</script>
将 :options='{group: "items"}'
添加到您的可拖动组件,或者您可以尝试添加属性 group="items"
(如果您使用的是 Vue 2.2+)