1
2

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]現在のパスを取得する

Posted at

#概要
現在のパスごとに、変数を入れ替えたり処理を変更したかったので、現在のパスを取得方法を調べました。
忘れないようにメモしたいと思います。

#実装

.js
const path = this.$route.path

#自分メモ
現在のパスによって変数を格納したい場合

.js
  data() {
    return {
      isActive: '',
    }
  },
  mounted() {
    const path = this.$route.path
    console.log(this.$route.path)
    if (path === '/'){
      this.isActive = '1'
    } else if (path === '/trend'){
      this.isActive = '2'
    } else if (path === '/item'){
      this.isActive ='3'
    }
  },

#参考文献
Vue.js】 現在のパス(URL)を取得する 【Vue-Router】

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?