我需要更改此設定,因為我已閱讀 nextTick 與延遲相比是更好的選擇。
這是運行良好的原始代碼:
methods: {
...mapActions(['fetchOverdraftLogs', 'setOverdraftFilters', 'fetchUserEventsCsvFile']),
},
computed: {
...mapGetters(['getOverdraftLogs'])
},
...
loadData: filters => {
const d = $.Deferred()
this.fetchOverdraftLogs({ params: this.filtersToSend(filters) })
.then(res => {
d.resolve(this.getOverdraftLogs)
this.setFilterValues()
})
return d.promise()
})
}
但是,我無法使用 nextTick 重新設計:
loadData: filters => {
this.fetchOverdraftLogs({ params: this.filtersToSend(filters) })
this.$nextTick(() => {
this.setFilterValues()
this.getOverdraftLogs
})
}
我需要確保網格在呼叫 API 后從狀態讀取資料。
你能幫忙嗎?
uj5u.com熱心網友回復:
延遲模式通常是一種反模式,尤其是對于 ES 承諾。它不是nextTick. 承諾已經是異步的,立即解決的承諾提供了一個小的延遲。nextTick提供足夠大的 DOM 更新延遲。
nextTick 支持承諾,但這里不需要。
它應該是:
loadData: filters => {
return this.fetchOverdraftLogs({ params: this.filtersToSend(filters) })
.then(() => {
this.setFilterValues()
return this.getOverdraftLogs;
})
}
Vuex 動作不應該回傳它們操作的資料,所以不應該有res.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/359406.html
標籤:javascript Vue.js Vuex 延期
