关于keep-alive的理解

关于keep-alive

首次进来 hook 的触发顺序 created-> mounted-> activated,退出时触发 deactivated
// 控制台打印结果
the hook of created is done!
the hook of mounted is done!
the hook of activated is done!
the hook of deactivated is done!

二次进来 hook 只触发 activated,退出时触发 deactivated
// 控制台打印结果
the hook of activated is done!
the hook of deactivated is done!

所以这就是为什么有些人开启 keep-alive 之后,createdmounted 注册的 pageInt 方法不触发的原因了,因为 keep-alive 把它们屏蔽了,也就是把数据缓存起来,所以不再请求。
如果你的某些页面一定要实时请求,你可以直接在 activated 这个 hookpageInt,就不要在 createdmounted 上面注册 pageInt 方法了。
还有你可以选择性 pageInt,比如监听状态变化,包括但不限于监听路由的变化,某参数的变化,某时间节点的变化等等。

猜你喜欢

转载自blog.csdn.net/jbguo/article/details/82835333