May 29, 2018
0
Level 1
Laravel mix, Reactjs and Axios give me error No 'Access-Control-Allow-Origin' .
I’m using Laravel Mix with Reactjs and Axios and I’m trying to fetch data from an external domain, but I get the error No Access-Control-Allow-Origin.
If I try without Laravel so only webpack, it is working. Anyone has an idea why i get this error only with Laravel Mix ?
Simple example:
import React, { Component } from 'react';
import Axios from 'axios';
export default class Example extends Component {
componentDidMount () {
this.fetchData();
}
fetchData () {
Axios.get(`https://api.coinmarketcap.com/v1/ticker/?limit=5`, {
method: 'get',
mode: 'no-cors'})
.then(res => {
console.log(res);
})
.catch(err => console.log(err));
}
render() {
return (
<div className="container">
<div className="row">
<div className="col-md-8 col-md-offset-2">
<div className="panel panel-default">
<div className="panel-heading">Example Component</div>
<div className="panel-body">
I am an example component!
</div>
</div>
</div>
</div>
</div>
);
}
}
Please or to participate in this conversation.