hello world~

Before what all don’t understand, write a front-end separation project, always encounter all kinds of problems need Baidu.

Now there are more projects.

Finally learned to Google.

/ / custom header axios. Interceptors. Request. Use (function (config) {  
    let token = getCookie(TOKEN_KEY)  
    if (token) {  
            config.headers.login_token = token  
    }  
    return config
})Copy the code

To solve

Problem: Cross-domain requests.

Why is the OPTIONS request sent?

In fact, cross-domain is divided into simple cross-domain request and complex cross-domain request

Simple cross-domain requests do not send OPTIONS requests

Complex cross-domain requests send a precheck request OPTIONS

Complex cross-domain requests must meet the following requirements:

2. The content-type of POST requests is not Application/X-www-form-urlencoded, multipart/form-data, or text/plain

3. Custom header fields are set in the request

If you don’t want to send option requests you can do simple requests like your Content-Type might be Application /json and change it to Application/X-www-form-urlencoded

source

Segmentfault.com/q/101000001…