【问题标题】:how to send a post request with params in nuxt.js?如何在 nuxt.js 中发送带有参数的发布请求?
【发布时间】:2021-06-24 18:18:55
【问题描述】:

我正在使用 fetch 方法 nuxt/axios 发送 post 请求以获取特定类别

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

但不起作用是否有另一种方法可以通过具有参数的发布请求获取数据

【问题讨论】:

    标签: api vue.js axios fetch nuxt.js


    【解决方案1】:

    要访问有关您当前路线的信息,您应该调用 $route 对象。

    如果你想访问在 URL 中传递的参数,那么你应该访问$route.query

    所以在你的情况下,你应该尝试调用一些东西

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

    【讨论】:

      猜你喜欢
      • 2019-04-28
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多