简体   繁体   English

使用 Vue Router 重定向到页面后如何重新获取 apollo 查询?

[英]How to refetch apollo query after i redirect to page with Vue Router?

I delete some resource in a page via apollo mutation:我通过 apollo 突变删除了页面中的一些资源:

async delete () {
  await this.$apollo.mutate({
    mutation: orderDelete,
    variables: {
      id: this.order.id
    }
  })

  this.$emit('success')
}

This is the method triggered by success emitter:这是success发射器触发的方法:

onOrderDeleted () {
  this.closeModal('modalOrderDelete')

  this.$nextTick(() => {
    this.redirectToClient()
  })
},
redirectToClient () {
  this.$router.push({
    name: 'clients.show',
    params: { clientKey: this.clientKey }
  })
}

Here is what happen: when the page is redirected to clients.show the order is still being show even if i deleted it, it only updates if i refresh the whole page.这是发生的事情:当页面被重定向到clients.show时,即使我删除了订单,它仍然会显示,只有在我刷新整个页面时才会更新。

So i would like to know how i trigger a query refresh when i redirect to this page?所以我想知道当我重定向到这个页面时如何触发查询刷新? Apollo is probably keeping data in cache and not updating it, i don't know how to update the cache only of this specific query, but all programatically because the user will be redirect via Vue Router. Apollo 可能将数据保存在缓存中而不是更新它,我不知道如何仅更新此特定查询的缓存,但所有这些都以编程方式进行,因为用户将通过 Vue 路由器重定向。

Note: clients.show shows a list of orders, so it should update the orders removing that one i just deleted, but it just doesn't change.注意: clients.show显示订单列表,因此它应该更新删除我刚刚删除的订单,但它不会改变。

this.$apollo.mutate() has more features than you used: this.$apollo.mutate()具有比您使用的更多的功能:

The object looks like this: object 看起来像这样:

this.$apollo.mutate({
  mutation: someGql,
  variables: {
    label: param1,
  },
  update: function(store, response) => {
    // how to update the store
  },
  optimisticResponse: theResponseYouExpect,
})

So, you sent the gql , but did not handle the response from that query (neither the real response from the server or the optimistic response (that you expect on success))因此,您发送了gql ,但没有处理来自该查询的响应(来自服务器的真实响应或乐观响应(您期望成功))

More on Vue Apollo mutation here .更多关于 Vue Apollo 突变 的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM