axios添加了header信息后发送的get请求自动编程option请求了

axios添加了header信息后发送的get请求自动编程option请求了

 

webpack 代理转发

 

Provisional headers are shown

 

 

 

在Vue中如何使用axios跨域访问数据

 

如果你是跨域请求,服务端返回响应时需要添加headers: Access-Control-Allow-Origin: *

express:

 

    // Website you wish to allow to connect
    res.setHeader('Access-Control-Allow-Origin', '*');
    // Request methods you wish to allow
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    // Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    res.setHeader('Access-Control-Allow-Credentials', true);


posted @ 2019-01-21 09:59  彭成刚  阅读(388)  评论(0编辑  收藏  举报