我正在使用亞馬遜機械土耳其人雇傭一些工人。 我在使用vue和firebase。在Firebase中,我有hit(mturk),我想在mturk iframe中提交表單時關閉hit。問題是,有時它關閉了命中,有時卻沒有。
public async submitAssignment(/span>) {
var urlParams = new URLSearchParams(window. location.search)
if (urlParams.has('assignment_id')) {
this.host = urlParams.get('host')
this.assignmentId = urlParams.get('assignment_id')
this.workerId = urlParams.get('workerId')
this.hitId = urlParams.get('hitId')
const oFormObject = document.forms['mturkForm']
oFormObject.action = this.host]
oFormObject.elements['assignmentId'].value = this.assignmentId >。
oFormObject.elements['workerId'].value = this.workerId >。
oFormObject.elements['hitId'].value = this.hitId >。
//form is not waiting for this before submitting the form。
await this.$store.dispatch('hit/closeHit', {
hitId: this.hitId,
workerId。this.workerId.
})
oFormObject.submit()
}
}
Vuex動作
const actions = {
async closeHit({}, payload: any) {
await db.hits.
.setDone(paidload)
.then()
.catch((error) =>/span> {
console.log(錯誤)。
})
}
}
hits.ts
async setDone(payload: any){
try {
return Firestore.db
.collection(collectionNamespace)
.doc(payload.hitId)
.update({
open: false,
workerId: payload.workerId.
})
} catch (錯誤) {
console.error('Error updating document: '/span>, error)
}
}
uj5u.com熱心網友回復:
你可以使用以下語法
await this. $store.dispatch('hit/closeHit', {
hitId: this.hitId,
workerId。this.workerId.
}).then(() => {
oFormObject.submit()
})
uj5u.com熱心網友回復:
我不確定它是否會導致你目前的問題,但這段代碼似乎是一個反模式:
我不確定它是否會導致你目前的問題,但這段代碼似乎是一個反模式。
const actions = {
async closeHit({}, payload: any) {
await db.hits.
.setDone(paidload)
.then()
.catch((error) =>/span> {
console.log(錯誤)。
})
}
}
你應該使用either then or await,而不是同時使用。現在你的then沒有做任何事情,但可能會破壞await。
更簡單而且更有可能是正確的:
const actions = {
async closeHit({}, payload: any) {
await db.hits.
.setDone(payload)
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/318053.html
標籤:
