Refer to the www.cnblogs.com/wasbg/p/109…
Take the interface that requests the CSDN as an example
- If requested directly, an error is reported, across domains.
/ / address
https://www.csdn.net/api/articles?type=more&category=home&shown_offset=1524276761019196&first_view=false
Copy the code
- The error message is as follows:
How to solve
- Create the vue.config.js file in the same directory as SRC and configure it as follows
- Target: indicates the domain name to be crossed
- ChangeOrigin: Indicates whether cross-domain is allowed
- PathRewrite: Rewrite the path, replace the API with empty, equivalent to the variable, write the path after the domain name concatenated
- When the request does not use the domain name [after configuring the proxy, it is because of the domain name here, resulting in a cross-domain error]
- Then you can request it
conclusion
Solve cross-domain problems through VUE proxy. Because the proxy configured the domain name for the first time, the request also carried the domain name, so it kept reporting cross-domain errors.