【发布时间】:2021-10-17 15:02:07
【问题描述】:
嗯,有一个简单的函数可以将加载程序的值设置为 true,然后在函数完成后将其设置为 false。但是有一个问题,我在 async/await async/await 函数中的等待没有等待具有 firebase batch writes 的代码。我的代码:
const updateNegotiation = async title => {
negotiationLoader.value = true
await store.dispatch('actionUpdateNegotiation', {
negotiation: listFromDialog.value,
title: title,
loader: negotiationLoader.value
})
negotiationLoader.value = false // the code doesnt await and put th loader's value to false
}
这是我的 batch writesfirebase 函数
//vuex
async actionUpdateNegotiation({commit}, deal){
const batch = db.batch()
const reference = db.collection('negotiations')
.doc(moduleUser.state.user.email)
.collection('deals')
const setRef = reference.doc(deal.title)
.collection('clients')
.doc(deal.negotiation.id)
batch.set(setRef, deal.negotiation)
batch.update(setRef, {
...deal.negotiation,
status: deal.title
})
const deleteRef = reference.doc(deal.negotiation.status)
.collection('clients')
.doc(deal.negotiation.id)
batch.delete(deleteRef)
try{
batch.commit()
return {
res: false
}
} catch (error) {
console.log(error);
return{
error,
res: true
}
}
}
【问题讨论】:
标签: javascript firebase vue.js google-cloud-firestore async-await