最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue router keep-alive and mounted behavior - Stack Overflow

programmeradmin2浏览0评论

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>?

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>?

Share Improve this question asked Oct 27, 2017 at 11:43 mt.andimt.andi 1531 silver badge12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 26

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;
  },
  ...
});
发布评论

评论列表(0)

  1. 暂无评论