Akryum / Akryum/vue-cli-plugin-apollo

How to integrate with Vuex

Offen
#66 9 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
question
Vorherrschende Sprache
JavaScript
Sterne
477
Forks
109
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.