我需要通过点击图标从Firebase中删除一个文档。问题是我不知道如何在vuetify中标记每个文档的特定ID
这是我的卡(1个项目可使用1张卡)
<v-card flat v-for="project in projects" :key="project.title">
<v-layout row wrap :class="`pa-3 project ${project.status}`">
<v-flex xs12 md6>
<div class="caption grey--text">Project title</div>
<div>{{ project.title }}</div>
</v-flex>
<v-flex xs6 sm4 md2>
<div class="caption grey--text">Person</div>
<div>{{ project.person }}</div>
</v-flex>
<v-flex xs6 sm4 md2>
<div class="caption grey--text">Due by</div>
<div>{{ project.due }}</div>
</v-flex>
<v-flex xs2 sm4 md2>
<v-btn flat color='red' slot='activator' class='right mx-0 my-0' @click='deleteProject()'>
<v-icon>delete</v-icon>
</v-btn>
<div>
<v-chip small :class="`${project.status} white--text caption mx-0`">{{ project.status}}</v-chip>
</div>
</v-flex>
</v-layout>
<v-divider></v-divider>
</v-card>
我尝试写这种方法
deleteProject() {
console.log('deleted');
let idP = element.id; // obviously that i have problem with this line
db.collection('projects').doc(idP).delete()
}
答案 0 :(得分:0)
我认为您是从projects
获取firebase
的,因此您始终会获取要获取的Firebase文档的ID。您应该将id
与其余的值一起存储。之后,当您调用deleteProject
函数时,可以像这样在函数中传递Id
。
<v-btn flat color='red' slot='activator' class='right mx-0 my-0' @click='deleteProject(project.Id)'>
然后像这样在您的函数中接收ID
deleteProject(Id) {
console.log('deleted');
db.collection('projects').doc(Id).delete()
}
希望这能解决您的问题。