7

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>

2 Answers 2

10

I found the solution...

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

Use route object instead of params in asyncData method.

Sign up to request clarification or add additional context in comments.

Comments

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.