当我在 NUXT 环境中运行此代码时:
const response = await useFetch('https://seasee-headless.local/wp-json/wc/v3/products', {
params: {
consumer_secret: 'cs_471cbb0635a300909b2b13ebd52d2550fc0c857e',
consumer_key: 'ck_ce1d0a5d3bf46ecbd46fdd18ba5f3fee41c094b4'
},
});
它给出以下结果:
{ "data": null, "pending": false, "error": "Error: [GET] \"https://seasee-headless.local/wp-json/wc/v3/products?consumer_secret=cs_471cbb0635a300909b2b13ebd52d2550fc0c857e&consumer_key=ck_ce1d0a5d3bf46ecbd46fdd18ba5f3fee41c094b4\": <no response> fetch failed", "status": "error" }
当我将
ssr:false
添加到 nuxt-config 文件中时,它就已经解决了。我对此很困惑。
我认为您尝试发布它,但它认为这是获取方法。 最好在 Usefetch 命令中选择方法,这样:
const response = await useFetch('https://Your address',{
method: "POST",
body: {
params: {
consumer_secret: 'cs_471cbb0635a300909b2b13ebd52d2550fc0c857e',
consumer_key: 'ck_ce1d0a5d3bf46ecbd46fdd18ba5f3fee41c094b4'
},
or your params directly
consumer_secret: 'cs_471cbb0635a300909b2b13ebd52d2550fc0c857e',
consumer_key: 'ck_ce1d0a5d3bf46ecbd46fdd18ba5f3fee41c094b4'
},
});
for Get methode just add you options directly after your url. like this:
const response = await useFetch('https://api.nuxtjs.dev/mountains', {
query: { param1, param2: 'value2' }
})
});