DEV Community

Sebastiangperez
Sebastiangperez

Posted on

2

Axios, Vue, Laravel and External Api

I like to know why using fetch works and using axos gives me a CORS error.
Im only using vue for fetching the data, i dont have any api from laravel, i just have a call from a simple componen on the mounted method and call it from the internal method like this :
mounted() {
this.fetch();
},
methods:{
fetch(){
axios.get('/search/shows?q=bluebook')
.then(function (result){
console.log();
})
}
}

if i do this, i got a cors error , if i switch from axios to fetch , works without a problem.

In the bootstrap.js file i have this:

window.axios.defaults.baseURL = 'http://api.tvmaze.com';
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
window.axios.defaults.headers.common['Access-Control-Allow-Origin'] = '';
window.axios.defaults.headers.common['Content-Type'] = 'text/plain';
window.axios.defaults.headers.common['Access-Control-Request-Method'] = '
';

also i tested using crossOrigin : true inside the get function but i got the same error.

there is a bug in axios? in laravel? im missing something here?

Thanks

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay