axios({方法:" post"})和axios.post()之间的区别

时间:2018-03-30 16:12:01

标签: javascript api shopify graphql axios

我使用Shopify Storefront API和Axios在本地开发电子商店。

Shopify在我使用axios()时给出回复,但在403 Forbidden执行相同操作时返回axios.post()

这两者之间的区别是什么?

axios.post(
    SHOPIFY_DOMAIN,
    {
    headers: {
        "Content-Type": "application/graphql",
        "X-Shopify-Storefront-Access-Token": SHOPIFY_TOKEN
    },
    data: `{ shop }`
})
axios({
  method: "post",
  url: SHOPIFY_DOMAIN,
  headers: {
    "Content-Type": "application/graphql",
    "X-Shopify-Storefront-Access-Token": SHOPIFY_TOKEN
  },
  data: `{ shop }`
})

1 个答案:

答案 0 :(得分:0)

axios.post的声明是axios.post(url[, data[, config]])。正确的使用方法是:

axios.post(
    SHOPIFY_DOMAIN,
    `{ shop }`,
    {
        headers: {
            "Content-Type": "application/graphql",
            "X-Shopify-Storefront-Access-Token": SHOPIFY_TOKEN
        }
    }
);

另请参阅:axios API