我正在开发一个应用程序,可用于创建任务并将它们放入列表中以有效地跟踪它们。我已经创建了列表和列表中的任务。
我正在尝试渲染属于列表内列表的所有任务。但是,当我为此编写 vue 代码时,我遇到了问题。我的代码不是渲染仅属于该列表的任务,而是生成数据库内的所有任务。有人可以帮助我找到仅渲染属于特定列表内的任务的正确方法吗?
DashboardView.vue
<template>
<div class="dashboard">
<Navbar class="navbar__dash" />
<h1 class="dashboard__welcome">Welcome {{ name }}</h1>
<div class="listview">
<div class="no__lists" v-if="len_list === 0">
<h2 class="no_lists">There are No lists here tap to add</h2>
</div>
<div class="has__lists" v-else>
<div class="all__lists" v-for="(item, index) in items" :key="index">
<div class="list">
<div class="title">
<div class="title__options">
<h1 class="list_name">{{ item[0].list_name }}</h1>
<Dropdown />
<!-- V-menu -->
<!--menu ends-->
</div>
</div>
<div class="body">
<div class="no_tasks" v-if="item[0].no_of_tasks === 0">
<h3>There are no tasks added yet</h3>
<router-link
class="createList"
:to="`/createTask/${id}/${item[0].list_id}`"
>
<fa class="list_plus" icon="fa-solid fa-plus" />
</router-link>
</div>
<div class="has_tasks" v-else>
<h4>Here are your tasks</h4>
<div class="tasks" v-for="(item, index) in items" :key="index">
<div
class="tasksforthis"
v-for="(task, index1) in item[1]"
:key="index1"
>
<div
class="filtered__tasks"
v-if:="`{{ item[0].list_id }} == {{ task.list_id }}`"
></div>
</div>
</div>
<router-link
class="createList"
:to="`/createTask/${id}/${item[0].list_id}`"
>
<fa class="list_plus" icon="fa-solid fa-plus" />
</router-link>
</div>
</div>
<div class="footer">
Number of Completed tasks: {{ item[0].no_completed }}/{{
item[0].no_of_tasks
}}
</div>
</div>
</div>
</div>
<router-link :to="`/createList/${id}`">
<fa class="plus__icon" icon="fa-solid fa-plus" />
</router-link>
</div>
</div>
</template>
<script>
import axios from 'axios';
import Dropdown from '@/components/DropdownList.vue';
import Navbar from '../components/NavBar.vue';
export default {
name: 'DashboardView',
data() {
return {
name: localStorage['name'],
len_list: 0,
items: [],
id: localStorage['id'],
};
},
methods: {
getTrackers() {
const path = 'http://localhost:5000/dashboard/' + localStorage['id'];
axios
.get(path)
.then((res) => {
this.items = res.data.list;
this.len_list = res.data.list[0][0]['len_list'];
console.log(res.data.list);
for (let i = 0; i < res.data.list.length; i++) {
console.log(res.data.list[i][1]);
for (let j = 0; j < res.data.list[i][1].length; j++) {
if (
res.data.list[i][1][j]['list_id'] ==
res.data.list[i][0]['list_id']
) {
console.log(res.data.list[i][1][j]['title']);
console.log(res.data.list[i][0]['list_id']);
}
}
}
})
.catch((err) => {
console.log(err);
});
console.log(this.items);
},
},
components: {
Navbar,
Dropdown,
},
created() {
this.getTrackers();
},
};
</script>
我通过 JSON 格式接收仪表板中的数据。示例数据可以是:
我的代码当前呈现如下:
但我希望待办事项列表包含 GO 和 Amaterasu 任务,海森堡应该只显示 GO、New 和 AK 任务等。即,我只希望列表呈现仅包含它的任务。 如果有人能告诉我如何正确渲染它,这对我来说非常有用。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
错误出现在这段代码
第一个 v-for 循环遍历您的每个项目(您已经在 div 上使用上面的 v-for 与 class="all__lists" 执行此操作以显示您的列表卡),第二个 v-for 循环遍历每个项目任务。
删除第一个 v-for,如下所示