vuejs / apollo

🚀 Apollo/GraphQL integration for VueJS
http://apollo.vuejs.org
MIT License
6.03k stars 522 forks source link

[Vue warn]: Property or method "$_apollo" is not defined on the instance #491

Open PayteR opened 5 years ago

PayteR commented 5 years ago

Hi, i still getting this error for unknown reason:

[Vue warn]: Property or method "$_apollo" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

Here is my config:

import Vue from 'vue'
import VueApollo from 'vue-apollo'
import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { setContext } from 'apollo-link-context'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { LocalStorage } from 'ttl-localstorage'

const httpLink = createHttpLink({
  uri: 'http://example.test/graphql',
  credentials: 'include'
})

const authLink = setContext(async (_, { headers }) => {
  // get the authentication token from local storage if it exists
  let token = await LocalStorage.get('token')
  // return the headers to the context so httpLink can read them

  return {
    headers: {
      ...headers,
      Cookie: 'XDEBUG_SESSION=phpstorm',
      Authorization: token,
      'X-Requested-With': 'XMLHttpRequest',
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    }
  }
})

const apolloClient = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
})

const apolloProvider = new VueApollo({
  defaultClient: apolloClient
})
Vue.use(VueApollo)

window.vue = new Vue({
  ...App,
  router,
  store,
  apolloProvider
}).$mount('#app')

Any ideas what could be wrong? thx

Akryum commented 5 years ago

Please provide a runnable reproduction so I can look into this issue, thanks!