跨域在根目录下建立JS文件:vue.config.js,添加一下代码
devServer: {
// overlay: { // 让浏览器 overlay 同时显示警告和错误
// warnings: true,
// errors: true
// },
// open: false, // 是否打开浏览器
// host: "localhost",
// port: "8080", // 代理断就
// https: false,
// hotOnly: false, // 热更新
proxy: {
'/apis': {
target: 'http://192.168.16.37:8083', // target host
ws: true, // proxy websockets
changeOrigin: true, // needed for virtual hosted sites
pathRewrite: {
'^/apis': '' // rewrite path
}
},
}
}
以上跨域是建立在proxy名称后的接口遵从跨域代理,
所以要跨域的地址记得加上以上属性名:proxy/接口地址,如:
/apis/trial/zftrialroom/getTrialMsg
在这说下axios的baseURL
在网上搜罗了一些代理报错的信息,如下:
Proxy error: Could not proxy request 接口地址 from 本地IP:8080 to 服务器IP:8083.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
有相关信息说设置了baseURL,会关闭代理服务
针对以上报错信息,我这边是因为服务器地址未开启
所以并不是配置参数少了或者错了。请相关人员开启服务器就好啦