配置代理
{
"/api": {
"target": "http://127.0.0.1:8081"
}
}
在package.json 中更改scripts 下面的start 命令
然后新建文件proxy.conf.json,
{
"/api": {
"target": "http://127.0.0.1:8081"
}
}
angular的服务器端口号是4200,默认访问http://127.0.0.1:8081是会跨域的,配置好后访问http://127.0.0.1:8081/api/...目录下的所有资源统一转接入到4200服务器来,实现了跨域请求;
注意配置好后要重新启动下服务器;
注意启动程序要用npm run start/npm start/或者scripts里start的代码启动即可
参考地址:https://jingyan.baidu.com/article/046a7b3e925ff4f9c27fa9dc.html