webpack 本地开发解决跨域

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin
'http://localhost:11000' is therefore not allowed access
原因:浏览器的同源策略不允许跨域访问,所谓同源策略是指协议、域名、端口相同。
解决:vue 可采用proxyTable解决。
 
proxyTable是什么?
vue-cli提供的解决vue开发环境下跨域问题的方法,proxyTable的底层使用了http-proxy-middleware(https://github.com/chimurai/http-proxy-middleware),它是http代理中间件,它依赖node.js,基
本原理是用服务端代理解决浏览器跨域:
dev: {

 // 静态资源文件夹
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/': {
target: 'http://192.168.77.165:8081', // 接口域名
changeOrigin: true, //是否跨域
pathRewrite: {
'^/': '/' //需要rewrite重写的,
}
}
},

 

 
host: '192.168.77.120',  //  本地ip
port: 8080,      //  本地端口
posted @ 2020-05-19 15:30  懵懵懂懂的小孩啊  阅读(464)  评论(0)    收藏  举报