Martin1182
3 months ago
742
1
Vue

AXIOS GET REQUEST

Posted 3 months ago by Martin1182

Hi, can you advise me? I'm trying to get an api in the VUE component. It still returns an error. The application runs in laravel. well thank you

mounted: function() {

   return axios(
            `https://newsapi.org/v2/top-headlines?sources=bbc- 
              news&apiKey=2a571f1425d44f8ab56de12e0e0e9b1b`,
            {
	    method: 'GET',
                mode: "no-cors",
                headers: {
                    "Access-Control-Allow-Origin": "*",
                    "Content-Type": "application/json"
                },
                withCredentials: true,
                credentials: "same-origin"
            }
        )
        .then(response => {
            this.posts = [];
            response.data.articles.forEach(posts => {
                this.posts.push(this.extractData(posts));
            });
        })
        .catch(response => {
            console.log(response);
        });

},

error:

Access to XMLHttpRequest at 'https://newsapi.org/v2/top-headlines?sources=bbc-news&apiKey=2a571f1425d44f8ab56de12e0e0e9b1b' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Please sign in or create an account to participate in this conversation.