Home » vue » how to send a post request with params in nuxt.js?

how to send a post request with params in nuxt.js?

Posted by: admin November 26, 2021 Leave a comment

Questions:

am using fetch method nuxt/axios to send post request to fetch specific category

async fetch() {
    const res = await this.$axios.post(
      `https://example.com/art-admin/public/api/get_single_cat_data_and_posts?cat_id=${params.id}`,
      {
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json"
        }
      }
    );
    this.categoryData = JSON.parse(JSON.stringify(res.data.Data));
  },

but not working is there another method to fetch data with post request that have parameters

Answers:

To access info about your current route you should call $route object.

If you want to access params passed in URL then you should access $route.query.

So in your case you should try to call something line

`https://example.com/art-admin/public/api/get_single_cat_data_and_posts?cat_id=${this.$route.query.id}`,