webpack 本地开发解决跨域
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin
'http://localhost:11000' is therefore not allowed access
原因:浏览器的同源策略不允许跨域访问,所谓同源策略是指协议、域名、端口相同。
解决:vue 可采用proxyTable解决。
'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,基
本原理是用服务端代理解决浏览器跨域:
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, // 本地端口
不言放弃,坚持梦想,愿每个人开心快乐。

浙公网安备 33010602011771号