server.dev.js中配置为 app.use('/finance/stock/hs', proxy({target:'http://web.juhe.cn:8080',changeOrigin:true}));
调接口为: axios({ method: 'get', url: '/finance/stock/hs?gid=&type=0&key=1ed6d144683a32812ebe646f31a8e62e' }).then(function (response) { console.log('response', response); if (response.status == 200 ) { } }).catch(function (err) { }); 得到的返回是200,但是却是html,如下:
loadScript("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function(){
if (window.hljs) {
window.hljs.initHighlightingOnLoad();
}
});
-->
回复 (6)
H
我用axios好像还没出现跨域问题,跨域问题网上很多解决办法,另外你贴出来的代码可能没有几个会认真看完。。。哈哈哈
L
虽然我不用react,但我感觉应该是你的 url 和 后端路由 冲突了
S
你把那行 app.use(...) 注释掉看看, 注掉如果结果一样就是proxy 没起效,检查下webpack 配置。 参考楼上的顺便检查下前后url冲突。
H
跨域使用代理?这还不如自己建一个服务器来请求远程地址,然后客户端直接请求你的服务器
W
跨域不难的,网上找找,你这贴的根本看不出来
参与回复
登录后即可参与回复。登录