什么是跨域?
在浏览器里面域名、端口、ip地址、协议,有任何一项不同,则跨域
A网站:http://localhost:8080/#/
B网站:http://localhost:3000/#/
处理跨域的方式?
JsonP
(只能处理get请求)、cors
(后端开启)、代理服务器
module.exports = {
devServer: {
host: 'localhost',
port: 8080,
proxy: {
'/api': {
target: 'http://localhost:3000',// 要跨域的域名
changeOrigin: true, // 是否开启跨域
},
'/get': {
target: 'http://localhost:3000',// 要跨域的域名
changeOrigin: true, // 是否开启跨域
}
}
}
}