Vue: keep-alive activated and deactivated hooks should trigger recursively when toggled

Created on 18 Nov 2016  ·  12Comments  ·  Source: vuejs/vue

feature request intend to implement

Most helpful comment

我也遇到这个问题,谁有解决办法??请告诉我,thank you

All 12 comments

Please be more specific on why you think it should work like that, and what use case are you running into that needs this. A single title doesn't qualify as a feature request.

很抱歉没有做更详细的说明,我们项目中的页面级组件都会带有设置页面meta属性的参数,当页面跳转时会自动设置这些属性,很自然他们是由activated/created来触发的,而在部分嵌套页面里,这个功能失效了,于是我们发现了这个问题。
keep-alive的组件在重新激活时,不会触发子组件的任何事件钩子,这导致在需要刷新子组件时,只能由父组件手动去触发,如果是多级嵌套的组件就会非常繁琐,所以希望keep-alive支持更细粒度的操作。
子组件随父组件activated/deactivated,他们理应触发这些钩子啊。

I have the same issue. Activated/Deactivated are called only on the components registered by router. So children of these components cannot benefit from activated/deactivated lifecycle hooks.

Do you think this will be in next releases?

同样的困惑,假如A跟B两个组件都有keep-alive。他们有共同的组件C,那么A初始化的时候C会执行一次create,B初始化的时候C同样会执行一次create。这时返回A,页面上的C组件不会触发任何生命周期的事件...假如C有个prop,A跟B都有传递,用watch监听这个prop也不会触发事件

@kinglion keep-alive的子组件目前不触发生命周期事件钩子,需要手动调用,调用方法参考callHook 方法

@nothinggift 嗯,这个也是一个hack方法 😊

keep-alive的子组件目前不触发生命周期事件钩子,需要手动调用,调用方法参考callHook 方法

这个就太麻烦的,我的页面现在全都是keep-alive的,每个页面根元素是个自己封装的组件,里面加了一些回调,比如动画结束之类的回调事件,如果需要手动去触发子组件的钩子,每个页面都得在activated函数里callHook,这个应该能在每个组件中配置是否触发子组件的钩子

我也遇到这个问题,谁有解决办法??请告诉我,thank you

you can remove it.

@Aierui How to remove it?

我的第三级路由组件 ,只能触发deactivated函数, activated不能触发,很奇怪啊,二级路由就都可以触发,下面是子路由插座的写法

<transition name="slide">
            <keep-alive>
                <router-view class="child-view"></router-view>
            </keep-alive>
</transition>

也遇到同样的问题,路由对应的入口组件里边的activated,deactivated钩子触发了,但是入口组件里边引用的子组件的deactivated,activated钩子都没有被触发

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robertleeplummerjr picture robertleeplummerjr  ·  3Comments

hiendv picture hiendv  ·  3Comments

gkiely picture gkiely  ·  3Comments

paceband picture paceband  ·  3Comments

paulpflug picture paulpflug  ·  3Comments