Nuxt Route Params

Apr 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>

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.