Apollo变量在promise`then内部不可访问

时间:2019-06-07 21:40:11

标签: javascript ecmascript-6 vuex vue-apollo

鉴于以下简化代码,我无法访问apollo内部的then

  logIn(context, { apollo, form }) {
    return signInMutation({ apollo, ...form }).then((response) => {
      apollo // undefined
    });
  });

我正在尝试通过以下代码访问apollo.provider。让我发疯的是,logOut没问题,但是logIn给了我这个错误。

vue-apollo.esm.js:1402 Uncaught (in promise) TypeError: Cannot read property '$apolloProvider' of null
    at DollarApollo.get (vue-apollo.esm.js:1402)
    at usersStore.js:46

完整代码

const actions = {
  logOut(context, apollo) {
    return signOutMutation({ apollo })
      .then(response => response.data)
      .then(response => {
        if(_get(response, 'signOut.success', false)) {
          localStorage.setItem(AUTH_TOKEN_KEY, '');
          context.commit('clearUser');
          return apollo.provider.clients.defaultClient.resetStore();
        }
      });
  },
  logIn(context, { apollo, form }) {
    return signInMutation({ apollo, ...form })
      .then(response => response.data)
      .then(response => {
        if(_get(response, 'signIn.success', false)) {
          const user = _get(response, 'signIn.user', {});

          localStorage.setItem(AUTH_TOKEN_KEY, user.authenticationToken);
          context.commit('logIn', user);
          return apollo.provider.clients.defaultClient.resetStore(); // line 46
        }
      });
  },
};

0 个答案:

没有答案