【发布时间】:2021-01-13 13:45:01
【问题描述】:
我正在尝试从 Firestore 中删除一个文档,但我认为它没有获取文档 ID。
当我点击 v-btn 时,它没有得到 :key 的 id。
我在这里从 Firestore 数据库中获取数据
<v-row v-for="shopItems in shopItem" :key="shopItems.id">
<v-col>
<p>{{shopItems.product}}</p>
</v-col>
<v-col>
<p>{{shopItems.catogorie}}</p>
</v-col>
<v-col>
<p>{{shopItems.price}}</p>
</v-col>
<v-col>
<v-btn @click="deleteItem(shopItems.id)">X</v-btn>
</v-col>
</v-row>
Vue js 数据()
shopItem: [],
product: '',
catogorie: '',
price: '',
userId: '',
我从另一个页面(同一个项目)得到了这个,什么有效,但这个函数只给我一个错误。
这是我的 Vue js 方法
methods: {
deleteItem(doc) {
db.collection("StoreCart").doc(doc).delete().then(function() {
console.log("Document successfully deleted!");
// location.reload()
}).catch(function(error) {
console.error("Error removing document: ", error);
});
}
},
created() {
firebase.auth().onAuthStateChanged(userId => {
if(userId) {
this.userId = firebase.auth().currentUser.uid;
db.collection("StoreCart").get().then((res) => {
res.docs.map((doc) => {
// console.log(doc.data().userId)
if(doc.data().userId == this.userId) {
this.product = doc.data().catogorie
this.catogorie = doc.data().catogorie
this.price = doc.data().price
this.shopItem.push({
product: doc.data().product,
catogorie: doc.data().catogorie,
price: doc.data().price
})
}
})
})
}
})
}
【问题讨论】:
-
在 Stack Overflow 上,不要分享文字图片。将文本复制到问题中并设置格式,以便于阅读、复制和搜索。
-
好的,谢谢。我会改的。
标签: javascript firebase vue.js google-cloud-firestore