A
A
Anton89892019-10-21 17:29:27
Vue.js
Anton8989, 2019-10-21 17:29:27

How to get data from server via axios?

Good day, I have the following code,

mounted() {
  axios 
    .get("http://anton77777.beget.tech/")
    .then(response => {
      if(response.data.error) {
         console.log(response.data.message)
      } else {
       // this.users = response.data.users
        console.log(response.data)
      }
    })
},

This error appears in the console -
Access to XMLHttpRequest at 'https://localhost:9002/admin/dist/companies' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
createError.js?2d83:16 Uncaught (in promise) Error: Network Error
    at createError (createError.js?2d83:16)
    at XMLHttpRequest.handleError (xhr.js?b50d:81)

I know that in the file located on the server, put That everything will work out correctly, can anyone know how to do without these file manipulations and write the correct code in vue.js? <?php header('Access-Control-Allow-Origin: *'); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sashqa, 2019-10-21
@Sashqa

Cross domain requests in Vue.js?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question