fix(vue-app): avoid multiple $fetch calls (#7129)

Co-authored-by: Aster <duda84@gmail.com>
This commit is contained in:
Pooya Parsa 2020-03-25 19:40:39 +01:00 committed by GitHub
parent b82f8d1640
commit 0f27f80c0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -52,7 +52,15 @@ function created() {
}
}
async function $fetch() {
function $fetch() {
if (!this._fetchPromise) {
this._fetchPromise = $_fetch.call(this)
.then(() => { delete this._fetchPromise })
}
return this._fetchPromise
}
async function $_fetch() {
this.<%= globals.nuxt %>.nbFetching++
this.$fetchState.pending = true
this.$fetchState.error = null

View File

@ -638,5 +638,7 @@ export function addLifecycleHook(vm, hook, fn) {
if (!vm.$options[hook]) {
vm.$options[hook] = []
}
vm.$options[hook].push(fn)
if (!vm.$options[hook].includes(fn)) {
vm.$options[hook].push(fn)
}
}