G
G
Gimir2020-09-09 12:53:16
Vue.js
Gimir, 2020-09-09 12:53:16

How to work (set, get from url) with GET parameters in Nuxt.js?

Hey! I ran into this problem: the page has a list of posts - /blog , you need to filter posts without changing the page, that is, with get parameters, the url in the browser should look something like this (I filter by tags), /blog?tag=frontend/ . I did not find any information on how to work with this in the docks of Nuxta, tell me how you implement such tasks?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2020-09-09
@Gimir

Hmm, are you sure you looked at the documentation?)

<nuxt-link :to="{name: 'blog', query: {tag: tag.id}}" v-for="(tag, i) in tags" :key="i">{{ tag.name }}</nuxt-link>

async asyncData({$axios, query}) {
    const posts = await $axios.$get('/api/blog', {
      params: {
        tag: query.tag,
      }
    })
    return {
      posts: posts.data,
    }
  },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question