Skip to content

$apollo.loading is not working in multiple components #1294

Answered by Akryum
sonphnt asked this question in Q&A
Discussion options

You must be logged in to vote

The implementation is left to you. You can for example use Vue.observable() to create a small reactive object that you can import in your components or in a global mixin.

const apolloState = Vue.observable({
  loading: 0,
})

Vue.mixin({
  computed: {
    $apolloGlobalLoading () { return apolloState.loading > 0 }
  }
})

const apolloProvider = new VueApollo({
  // Watch loading state for all queries
  // See 'Smart Query > options > watchLoading' for detail
  watchLoading (isLoading, countModifier) {
    apolloState.loading += countModifier
    console.log('Global loading', loading, countModifier)
  },
})
<template>
  <div v-if="$apolloGlobalLoading">Loading some query...</div>
</template>

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Akryum
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
6 participants
Converted from issue

This discussion was converted from issue #988 on November 29, 2021 18:00.