6

I try to fetch value of the name parameter in URL: http://fakelocalhost:3000/page?name=test

I'm using NuxtJS (v2.11.0) and TypeScript, with nuxt-property-decorator package (v2.5.0).

But, I get an undefined result with console.log(params.name).

Here, my full TS code:

<script lang="ts">
  import {
    Component,
    Vue
  } from "nuxt-property-decorator";

  @Component({
    asyncData({ params  }) {
      console.log(params.name);
    }
  })
  export default class extends Vue {}
</script>
Ahmad Mobaraki
  • 7,426
  • 5
  • 48
  • 69
pirmax
  • 2,054
  • 8
  • 36
  • 69

2 Answers2

9

I found the solution...

asyncData({ route }) {
   console.log(route.query.name);
}

Use route object instead of params in asyncData method.

pirmax
  • 2,054
  • 8
  • 36
  • 69
6

You can also use the context parameter: query https://nuxtjs.org/docs/2.x/internals-glossary/context#query

asyncData({ query }) {
   console.log(query.name);
}
kalak
  • 71
  • 1
  • 1