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,如下:
<!–html just for develop server–>
<!DOCTYPE html>
<html lang=“zh-cn”>
<head>
<meta charset=“UTF-8” />
<meta http-equiv=“X-UA-Compatible” content=“IE=edge,chrome=1”>
<meta name=“viewport” content=“width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0” />
<link rel=“stylesheet” href=“https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css”>
<link rel=“stylesheet” href=“https://unpkg.com/purecss@1.0.0/build/pure-min.css” integrity=“sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w” crossorigin=“anonymous”>
<title>人傻钱多股票交易网</title>
</head>
<body>
<div id=“app”></div>
<script src="/dev/bundle.js"></script>
<!-- <script>
function loadScript(url, callback){
var script = document.createElement (“script”)
script.type = “text/javascript”;
if (script.readyState){
script.onreadystatechange = function(){
if (script.readyState == “loaded” || script.readyState == “complete”){
script.onreadystatechange = null;
callback();
}
};
} else {
script.onload = function(){ callback() };
}
script.src = url;
document.getElementsByTagName(“head”)[0].appendChild(script);
}
loadScript("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function(){
if (window.hljs) {
window.hljs.initHighlightingOnLoad();
}
});
</script> --> </body> </html>,求帮助,该怎么解决跨域问题
跨域不难的,网上找找,你这贴的根本看不出来
我用axios好像还没出现跨域问题,跨域问题网上很多解决办法,另外你贴出来的代码可能没有几个会认真看完。。。哈哈哈
虽然我不用react,但我感觉应该是你的 url 和 后端路由 冲突了
你把那行 app.use(…) 注释掉看看, 注掉如果结果一样就是proxy 没起效,检查下webpack 配置。 参考楼上的顺便检查下前后url冲突。
跨域使用代理?这还不如自己建一个服务器来请求远程地址,然后客户端直接请求你的服务器