Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch query string value from URL with NuxtJS and AsyncData method

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>
like image 914
pirmax Avatar asked Jul 17 '26 04:07

pirmax


1 Answers

I found the solution...

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

Use route object instead of params in asyncData method.

like image 167
pirmax Avatar answered Jul 18 '26 18:07

pirmax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!