Vue Apollo 重新获取事件查询

Vue Apollo refetch query on event

我的组件实例中有一个查询:

@Component({
  apollo: {
    cartProducts: {
      query: GET_CART_PRODUCTS,
      loadingKey: "loading",
    },
  }
})

它正在正确加载我的数据。然后我更改我的数据库中的数据并希望在单击时重新获取它们,这调用了该函数:

  refresh() {
    this.$apollo
      .query({
        query: GET_CART_PRODUCTS,
      })
      .then((res: any) => (this.cartProducts = res.data.cartProducts))
      .catch((err: any) => console.log(err));
  }

但它不会更新 cartProducts 属性,也不会给我任何错误。虽然如果我刷新我的页面,新数据就在那里。在我的 Apollo 配置中,我有这样的 属性 fetchPolicy: "network-only"。这种行为的原因是什么?提前致谢!

答案很简单,不好意思打扰了,我只好google再说了。

   this.$apollo.queries.cartProducts.refetch()