gitee或github都行,上传个json文件后前端用fetch接口请求返回文件里的数据。我试了gitee,在地址栏访问数据可以,用接口请求就不行了。github吧是响应失败
<script>
//网上找一个跨域代理服务器,或自己搭一个
const proxy = "https://bird.ioliu.cn/v2?url=";
function get_json_value(){
let url = "https://gitee.com/churuxu/project_template/raw/master/template/cxx_console_application/.vscode/c_cpp_properties.json";
fetch(proxy + url).then((res)=>{
res.json().then((obj)=>{
console.log(obj);
});
});
}
</script>
<button onclick="get_json_value()">get json</button>
跨域问题,你需要解决跨域问题 。我试了下 axios ,ajax 都不行(尝试了 jsonp,设置允许跨域都不行) 。只能 使用代理 ,你自己写代理,服务端和前端 都行。 不过 如果 gitee 不允许跨域的话,那就 没办了。你还是想其他方案吧。
这个问题可能是由跨域问题导致的。
当从不同的域名或端口请求资源时,会产生跨域问题。解决方法
参考:https://stackoom.com/question/16bYX/在package-json中使用git-URL依赖分支或标记