The following error is usually reported across domains

Condition for cross – domain error reporting is reached

If the IP addresses of A and B are different, the request is cross-domain. (Cross-domain requests do not necessarily report errors.)

Cross-domain request error condition: the browser’s same-origin policy and request are of Ajax type (breaking one of them will not cause an error)

Cross-domain solutions:

  1. Cors Chrome Extension (Personal development only)

  2. Back-end write code (CORS) adds the necessary response headers to the response, and the browser does not report an error when the response comes back

  3. Proxy forwarding (sending requests to a proxy server, which processes cross-domain requests before sending them to the target service starting with /API)

Back-end processing methods

Proxy forwarding: a cross-domain solution in vUE projects

1. Change dev base address to local address: ‘/ API ‘(must write/API)

2. Add the code to vue.config.js

Proxy: {/ / with/API if the request address; agents out of the trigger mechanism / / http://localhost:9588/api/login - > http://localhost:3000/api/login '/ API: {target: 'http://localhost:3000' // the real interface address we want to delegate}}Copy the code

3. Be sure to comment out the mock request address otherwise it will also fail

// before: require('./mock/mock-server.js')
Copy the code

4. BaseURL in the request is written as:

BaseURL: process.env.vue_app_base_api, // Sets the base address of the base of the AXIos requestCopy the code

Salute to my every day as a coder!!