vue proxy跨域配置
vue前后端分离跨域配置前后端分离项目中、前端请求后端接口时,存在违反同源策略(协议、域名、端口)。vue代理proxy解决跨域eg:后端接口:http://localhost:12911解决:在根目录新建或在vue.config.js中配置module.exports = {devServer: {proxy: {"/api": {target: 'http://localhost:12911'
·
vue前后端分离跨域配置
前后端分离项目开发中、前端请求后端接口时,存在违反同源策略(Same origin policy)是一种约定(协议、域名、端口)。
vue配置代理服务器proxy解决跨域
eg:后端接口:http://localhost:12911
解决:在根目录新建或在vue.config.js中配置
module.exports = {
devServer: {
proxy: {
"/api": {
target: 'http://localhost:12911', //目标接口域名
secure: false, //false为http访问,true为https访问
changeOrigin: true, //是否跨域
//重写路径
pathRewrite: {
'^/api': 'http://localhost:12911'
},
},
},
},
页面调用
```axios.post(’/api/user-registration’, params)``
打包后proxy代理失效
更多推荐
已为社区贡献1条内容
所有评论(0)