LoginSignup
23
16

More than 5 years have passed since last update.

NuxtJSでURLパラメータを取得する方法

Posted at

nuxt.jsでURLパラメータを取得したい時があったので調べてみました。

pages配下に以下のような階層構造を作成した時、最下層のnew.vueにアクセスするURLが orders/orderId/offers/new のように作成される。

pages
  └── orders
      └── _orderId
          └── offers
              └── new.vue

このときの orderId を取得する。

new.vue
<template>
  {{ $route.params }}    // 1
</template>

<script>
export default {
  created: function() {
    console.log(this.$nuxt.$route.params.orderId)    // 1
  }
}
</script>
23
16
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
23
16