Akryum / Akryum/vue-cli-plugin-apollo

How to integrate with Vuex

未关闭
#66 9 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
question
主要语言
JavaScript
星标
477
派生
109
PR 合并指标
30 天内没有已合并 PR

描述

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?

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。