devServer: {
proxy: {//配置跨域
'/api': {
target: 'http://devote.com:8009',
changeOrigin:true, // 是否需要跨域
pathRewrite: {'^/api' : ''} // 使用了这句之后: /api/detail 现在会被代理到请求 http://localhost:3000/detail
}
}
}
配置如上,按道理来说,我们写的接口地址,如/api/detail走完代理应该会变为
http://devote.com:8009/detail
但是我请求的接口还是 http://devote.com:8009/api/detail
为什么呢?
后来发现是因为我们的baseUrl,
const service = axios.create({
//baseURL: Config.ajaxUrl,
timeout: 10000
})
创建axios对象的时候,指定了baseURL,把此对象注释掉,即可
暂无评论
要发表评论,您必须先 登录