vue前端跨域(记录一下)
修改config文件夹的index.js
为了让后端能够访问到前端的资源,需要配置跨域支持。
在config\index.js 中,找到 proxyTable 位置,修改为以下内容:
proxyTable: {
'/api': {
target: 'http://localhost:8443',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
eg:
proxyTable: {
'/user': {
target: 'http://127.0.0.1:8081',
//port:8081,
ws: true,
changeOrigin: true
},
},
注意:修改完配置文件必须重启项目才能生效。