简体   繁体   English

Vue路由器保持活动和挂载行为

[英]Vue router keep-alive and mounted behavior

I had some logic in the mounted() method before I started using <keep-alive> .在我开始使用<keep-alive>之前,我在mounted()方法中有一些逻辑。 For instance: document.title = this.title .例如: document.title = this.title Now the title changes upon the first load only.现在标题仅在第一次加载时更改。

I could listen for route changes, but it won't work when you land on the page.我可以监听路线变化,但是当你登陆页面时它就不起作用了。

What is the proper way to detect loading of another component in <keep-alive> ?检测<keep-alive>中另一个组件的加载的正确方法是什么?

Move your logic to the activated lifecycle hook, which is called whenever a keep-alive component is activated.将您的逻辑移动到activated的生命周期钩子,只要激活了保活组件,就会调用该钩子。

For example:例如:

new Vue({
  ...
  activated: function() {
    document.title = this.title;
  },
  ...
});

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

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