【发布时间】:2020-01-11 16:39:16
【问题描述】:
我有以下代码。我想要做的是在执行调度之前等待值完成。 发生的事情是它调度并且只能获取第一个值而不是以下 foreach。
提前致谢
syncPO() {
this.wait = true
this.$store.dispatch('account/checkToken', this.optionValues.syncValue).then((res) => {
this.wait = 'stepTwo'
this.max = res.length
res.forEach(result => {
this.POValues.po_number = result.DocNumber
this.POValues.vendor_id = result.VendorRef
this.POValues.order_date=result.MetaData.CreateTime
this.POValues.amount=result.TotalAmt
this.POValues.currency=result.CurrencyRef
this.POValues.qb_poId=result.Id
this.POValues.status=result.POStatus
this.POValues.line = result.Line
this.$store.dispatch('purchaseOrder/createPO',this.POValues).then(res=>{
// console.log(this.POValues.line)
this.value += 1;
}).then((res)=>{
this.$store.dispatch('purchaseOrder/create-lists')
})
})
})
},
【问题讨论】:
-
尝试使用 Promise。 link
标签: javascript json vue.js