vue apollo 订阅的生命周期是什么?
What is the lifecycle of vue apollo subscriptions?
当视图更改时,vue-apollo
会自动取消订阅查询吗?
例如,我有两个视图路由到 /users
和 /orders
。 /users
订阅了 users
table,/orders
订阅了 orders
table。
如果我在 /user
页面上,order
订阅是否仍然有效?如果是,我该如何关闭它?
由于 Apollo 查询绑定到您的组件,它们将遵循组件的生命周期,即如果您的路由更改(呈现不同的组件),您的旧组件将被删除,因此您的旧查询也将被删除。
这由 this mixin 在 Vue apollo 中处理。
看看下面的部分:
export function installMixin (Vue, vueVersion) {
Vue.mixin({
// Other irrelevant code for this question
destroyed: destroy,
})
}
这意味着它绑定到每个 Vue 组件的 'destroyed' 事件,然后将触发 destroy 函数(由 Vue API reference 定义):
function destroy () {
if (this.$_apollo) {
this.$_apollo.destroy()
}
}
所以这个过程确保你的查询被销毁并且当你的组件被销毁时不再有效。
我希望这能回答您的问题
当视图更改时,vue-apollo
会自动取消订阅查询吗?
例如,我有两个视图路由到 /users
和 /orders
。 /users
订阅了 users
table,/orders
订阅了 orders
table。
如果我在 /user
页面上,order
订阅是否仍然有效?如果是,我该如何关闭它?
由于 Apollo 查询绑定到您的组件,它们将遵循组件的生命周期,即如果您的路由更改(呈现不同的组件),您的旧组件将被删除,因此您的旧查询也将被删除。
这由 this mixin 在 Vue apollo 中处理。
看看下面的部分:
export function installMixin (Vue, vueVersion) {
Vue.mixin({
// Other irrelevant code for this question
destroyed: destroy,
})
}
这意味着它绑定到每个 Vue 组件的 'destroyed' 事件,然后将触发 destroy 函数(由 Vue API reference 定义):
function destroy () {
if (this.$_apollo) {
this.$_apollo.destroy()
}
}
所以这个过程确保你的查询被销毁并且当你的组件被销毁时不再有效。
我希望这能回答您的问题