【发布时间】:2020-12-19 06:13:12
【问题描述】:
我正在尝试使用 firebase 在 Vue 中创建一个实时投票应用程序来存储投票数。我能够创建数据库并增加投票数,以及将来自数据库的最新投票显示到我的应用程序。但是,当我单击按钮将投票数更新为 1 时,投票仅在浏览器中增加,而不是在 firebase 上。
我是不是用的更新功能不对?
...methods:{
upVotePingu() {
let pingu = db.collection('canidates').doc('pingu')
// Atomically increment the population of the city by 50.
pingu.set({
votes: this.pingu.votes++
})
console.log('voted')
}
...mounted(){
db.collection('canidates')
.get()
.then(query => {
query.forEach(doc => {
const dbVote = {
vote: doc.data().votes
}
this.pingu.votes = dbVote.vote
console.log(this.pingu.votes)
})
})
<button @click="upVotePingu">Vote</button>
data() {
return {
pingu: {
votes: 0
}
}
【问题讨论】:
标签: javascript firebase vue.js google-cloud-firestore