Nuxt.js, problem with fetching data in async fetch() hook

971 views Asked by At

I'm having some trouble fetching data from my API in both the async fetch() hook and async data(). I get the error: "Error: connect ECONNREFUSED". If I try to fetch the data in the mounted() hook instead, it works normally. I've built the API in Lumen and when I've tried with a different API(which I've also built in Lumen and is running online) it also worked normally. I'd assume the problem is in the API, but I don't understand how is it working in mounted() then. I've tried using both axios and $http and I get the same result.

UPDATE I've tried putting in "fetchOnServer: false" and it works like that, so it looks like the problem is with fetching data on the server side.

1

There are 1 answers

0
cesarecluka On

If someone sees this and has the same problem, the solution for me was to start the lumen application with: php -S 127.0.0.1:8000 -t public instead of php -S http://localhost:8000 -t public