Akryum / Akryum/vue-cli-plugin-apollo

How to integrate with Vuex

Aperta
#66 9 commenti 2 reazioni 0 assegnatari Vedi su GitHub
question
Lingua principale
JavaScript
Stelle
477
Fork
109
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I'm currently trying to fire off a graphQL query from inside Vuex using the apollo plugin. My store.js file looks like this:

```javascro[t
import Vue from 'vue';
import Vuex from 'vuex';
import gql from 'graphql-tag';
import { createProvider } from './vue-apollo';

const provider = createProvider();
const { apolloClient } = provider;

Vue.use(Vuex);

export default new Vuex.Store({
state: {

},
mutations: {

},
actions: {
getPosts: () => {
apolloClient
.query({
query: gql`
query {
_id
title
imageUrl
}
`
})
.then(data => console.log(data))
.catch(err => console.error(err))
}
},
});
```
But I keep on getting erors from chrome developer tools stating that it is unable to read the query property of undefined. I know that I am possibly messing this up royally, but what should I import at the top of this file to make it work?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.