Nuxt Route Params

April 10, 2020

Edit pages/samples/_id.vue

<template>
  <div>
    <h1>ID: {{ $route.params.id }} == {{ pageId }}</h1>
  </div>
</template>

<script>
export default {
  /*
  validate ({ params }) {
    // Must be a number
    return /^\d+$/.test(params.id)
  },
   */
  async asyncData ({ $axios, params }) {
    const { data } = await $axios.get(`/data/page-${params.id}.json`)
    return data
  },
  data() {
    return {
      pageId: parseInt(this.$route.params.id)
    }
  }
}
</script>
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.