鉴于以下简化代码,我无法访问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
}
});
},
};