LoginSignup
3
1

More than 3 years have passed since last update.

Vue.js URLからidを取得

Posted at

例えば以下の?がつくURLで1を取得したい場合

http://localhost:3000/maps?tweet_id=1

クエリパラメーターと言うみたいです
これで1が取得できます

<template>
<div id="app">
  {{$route.query.tweet_id}}
</div>
</template>

詳細ページでよく見る以下のURLでは

http://localhost:3000/tweets/1

これで良いと思います

<template>
<div id="app">
  {{$route.params.id}}
</div>
</template>

おまけ

axiosでJSONデータを取得するときなどはthisをつけると取得できます

      axios
        .get(`/api/v1/tweets/${this.$route.params.id}/index.json`)
        .then(response =>{
          this.analyses = response.data;
        })
3
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
3
1