-
-
Notifications
You must be signed in to change notification settings - Fork 522
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
$apollo.loading is not working in multiple components #988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue has been present in apollo for almost 3 years now. See #1314 |
I am still seeing this issue. |
Jep. Same here. |
Did anyone figure out a solution for this? |
This is expected behavior: const apolloProvider = new VueApollo({
// Watch loading state for all queries
// See 'Smart Query > options > watchLoading' for detail
watchLoading (isLoading, countModifier) {
loading += countModifier
console.log('Global loading', loading, countModifier)
},
}) |
@Akryum thanks so much for clarifying. I've got the loading indicator logged in the console now. What i can't work out now from the docs is how to access that loading state in any template? |
The implementation is left to you. You can for example use 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> |
Fantastic that worked @Akryum . Then in nuxt.config.js: modules: [
'@nuxtjs/apollo',
'@nuxtjs/observable'
],
apollo: {
includeNodeModules: true,
watchLoading: '@/apollo/loadingHandler.js'
}, @/apollo/loadingHandler.js: export default (isLoading, countModifier, nuxtContext) => {
isLoading += countModifier
nuxtContext.$state.loading += countModifier;
} /state.js export default() => ({
loading: 0,
}) then in your templates you can use <loading-icon :is-loading="$state.loading"></loading-icon> |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
I have 2 components, one global component in the top right corner with spinner, and product component when users navigate to "/products".
In the product component, I have a call to graphql with apollo and $apollo.loading is working fine. I can see my loading bar work in this component.
But in global component, my spinner never shows with $apollo.loading.
<div v-if="$apollo.loading"><span class="spinner"></span></div>
I want my spinner in the top right corner showing when there are any queries to graphql server.
Is this a bug or I missed some configuration?
Thanks
Versions
vue: 2.6.11
vue-apollo: 3.0.3
apollo-client: 2.6.8
The text was updated successfully, but these errors were encountered: