0

When I use the Vue with axios to request my remote server, I found a error showed such message:

Access to XMLHttpRequest at 'http://www.example.com' from origin 'http://192.168.1.201:8080' 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.

then I had searched in Bing with the Key Word CORS , and it said that I need to add header Access-Control-Allow-Origin,But I tried and found it doesn't works.

here is my code:

const axios = require('axios')
axios.get('http://www.example.com',{
    mode: 'no-cors',
    headers: {
        "Access-Control-Allow-Origin":"http://localhost:8080",
        "Access-Control-Allow-Methods":"GET",
        "Access-Control-Allow-Headers":"Content-Type"
    }
}).then(res => {
    console.log('StatusCode: ${res.statusCode}')
})

plus:

I'm using Electron v11, Node v15.8.0, Vue 3, axios 0.18.0

English is not my native language; please excuse typing errors.

undefined
  • 7
  • 1
  • 4

0 Answers0