简体   繁体   中英

Vue router keep-alive and mounted behavior

I had some logic in the mounted() method before I started using <keep-alive> . For instance: 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> ?

Move your logic to the activated lifecycle hook, which is called whenever a keep-alive component is activated.

For example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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