When i run this code in NUXT environment:
当我在NUXT环境中运行此代码时:
const response = await useFetch('https://seasee-headless.local/wp-json/wc/v3/products', {
params: {
consumer_secret: 'cs_471cbb0635a300909b2b13ebd52d2550fc0c857e',
consumer_key: 'ck_ce1d0a5d3bf46ecbd46fdd18ba5f3fee41c094b4'
},
});
It gives following result:
它提供了以下结果:
{ "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" }
When i add ssr:false
to nuxt-config file , then it has been resolved. I'm confused with that.
当我将SSR:FALSE添加到nuxt-config文件时,它已经被解析了。我对此感到困惑。
更多回答
The issue is probably not coming from the place you're showing in your question. There is no reason that this request would fail.
问题可能不是来自您在问题中显示的位置。这个请求没有理由会失败。
优秀答案推荐
I think you try to Post it but it consider that as th Get methode.
It is better to choose the methode in your Usefetch command so:
我认为你试图发布它,但它认为这是获得方法。最好在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' }
})
});
What version of node are you using? I was experiencing similar problems, and switching to a "newer" node version solved everything.
您使用的是什么版本的节点?我也遇到了类似的问题,切换到“较新”的节点版本解决了所有问题。
更多回答
我是一名优秀的程序员,十分优秀!