我创建了一个使用 Vuetify、Vuex 和 vuedraggable 的 Vue 应用程序。通过拖放包含相关信息的 v-card 组件按预期运行,但我无法找到识别目的地的方法,以便我可以更新 Vuex Store
<template>
<v-container>
<v-row justify='center'>
<v-col v-for="stage in stages" :key="stage.value">
<span class="card-text-bold">{{ stage.heading }}</span>
<draggable :list="buckets[stage.name]" group="openTasks" :move="handleStatus">
<v-card color="commentCard" class="list-group mt-3" v-for="task in buckets[stage.name]" :key="task._id">
<v-card-text>
<span class="card-text-bold">{{ task.title}}</span>
</v-card-text>
<v-card-text>
<span class="card-text"> {{ task.description}} </span>
</v-card-text>
<v-card-text>
{{ task.assignee}}<v-icon right @click="goToTask(task._id)">edit</v-icon>
</v-card-text>
</v-card>
</draggable>
</v-col>
</v-row>
</v-container>
</template>
<script>
import { mapGetters } from 'vuex';
import draggable from 'vuedraggable';
import moment from 'moment';
export default {
name: 'Tasks',
components: {
draggable
},
data() {
return {
stages: [
{ heading: 'Created', name: 'created' },
{ heading: 'Assigned', name: 'assigned' },
{ heading: 'In Progress', name: 'in progress' },
{ heading: 'On Hold', name: 'on hold' },
{ heading: 'Complete', name: 'complete' },
{ heading: 'Closed', name: 'closed' }
]
};
},
created() {
this.handleGetTasks();
},
computed: {
...mapGetters(['user', 'loading', 'tasks', 'buckets'])
},
methods: {
getTimeFromNow(time) {
return moment(new Date(time)).fromNow();
},
goToTask(taskId) {
this.$router.push(`/task/${taskId}`);
},
handleGetTasks() {
const userRole = localStorage.getItem('role');
const fullname = localStorage.getItem('fullname');
switch (userRole) {
case 'Manager': {
this.$store.dispatch('getAllTasks');
break;
}
case 'Requester': {
this.$store.dispatch('getRequestTasks', {
fullname: fullname
});
break;
}
case 'Assignee': {
this.$store.dispatch('getAssignTasks', {
fullname: fullname
});
break;
}
}
},
stateTasks(target) {
console.log('state', target);
if (this.buckets[target] > 0) return this.buckets[target];
else return [];
},
handleStatus(evt) {
const movedId = evt.draggedContext.element._id;
var targetStage;
console.log('source', movedId, 'target', Object.keys(evt.relatedContext.list));
}
}
};
</script>
此处使用的数据源列表是“buckets”对象,其中包含每个任务阶段的任务数组。拖放将任务卡从源移动到目标,但我已经能够找到一种方法来识别目标列表。
请提供有关如何确定在移动后应该更新“buckets”对象中的哪些列表的建议。
谢谢
德斯