How to solve the cross-domain problem at the front end

most interviewers like to ask this question very much. no, no, no. Is there any way to solve it?
I have heard some people say that proxies can be configured in vue cli. However, it is said on the Internet that after the launch, the agent will still become cross-domain. (meaning not effective)

Mar.12,2021

this general answer is fine with two points:
1.jsonp
2.CORS
learn about
other ways such as postMessage, websocket, hash, and so on


of course, the front end works with the back end to solve cross-domain problems. If ajax is cross-domain, most of the back-ends are done after a while, and the front end hardly needs to do anything.


throw the pot to the backend. It is really not possible to jsonp, window.name or modify document.domain to cross subdomains, and use the newly introduced window.postMessage method in HTML5 to transfer data across domains


Development phase

vue cli Agent configuration

config/index.js

  https://codeshelper.com/a/11.

Menu