簡體   English   中英

vue-apollo 在路由器防護中執行 graphql 查詢

[英]vue-apollo execute graphql query in router guard

我有一個應用程序,用戶可以在其中注冊活動。 一旦用戶注冊,他就可以訪問以前無法訪問的路線。

我正在為我的 api 請求使用 graphql。 我的路線守衛中的代碼如下所示:

router.beforeEach(async (to, from, next) => {
  if (to.meta.signUpRequired && from.name) {
    const { data: { getCurrentUser } } 
      = await apolloProvider.defaultClient.query({
      query: USER_INFO_QUERY
    });
    if (getCurrentUser && getCurrentUser.isCollectionAttendee) {
      return next();
    }
    return next('/');
  }
  return next();
});

這工作正常,並且不會在每次路由更改時執行請求,因為 vue-apollo 緩存了結果。 我的問題是,如果用戶注冊然后嘗試切換路由,他不能,因為仍然使用查詢的緩存結果。

我不想在每次路由更改之前使用僅限網絡的 fetchPolicy。

我該如何解決這個問題?

也許在注冊后嘗試使用this.$apolloProvider.defaultClient.resetStore()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM