1. The error in the front-end browser is as follows:
Access to XMLHttpRequest at http://xxx.xxx from origin "http://localhost:8000" has been blocked by CORS policy: Response to preflight request doesn"t pass access control check: Redirect is not allowed for a preflight request.
2.axios encapsulation
- modified on the basis of encapsulation
// axios
const service = axios.create({
baseURL: process.env.BASE_API, // api base_url
timeout: 5000, //
headers: { "Content-Type": "multipart/form-data" }
})
//headersoptions
if (config.method === "post") {
config.data = qs.stringify({
...config.data
})
}
//
but after modification, an options will still be sent for the first time, and the request for options is 302
.