0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

vue-routerでページ遷移を毎回検知したい

Posted at

方法は簡単で、$routeをwatchしてあげれば良いらしい。

<template>
     <router-view></router-view>
</template>

<script>

export default {
  watch: {
    '$route': function (to, from) {
      if (to.path !== from.path) {
        
      }
    }
  }
};
</script>

router-viewを使っているページに記述しておけば、ページ遷移毎に好きな処理を実行させることができる。

もしこの方法がアンチパターンだよって方がいましたら、ぜひコメントしてくださいm(_ _)m

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?