Vue开发中如何解决跨域访问配置难题?
- 内容介绍
- 文章标签
- 相关推荐
本文共计175个文字,预计阅读时间需要1分钟。
Vue开发环境跨域访问其他服务器或本地其他端口,需要在项目中配置config/index.js文件,修改如下:
javascriptmodule.exports={ dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api': { target: 'http://localhost:8080', // 修改为其他服务器的地址和端口 changeOrigin: true, pathRewrite: { '^/api': '' } } } }}
Vue开发环境跨域访问其他服务器或者本机其他端口,需要配置项目中config/index.js文件,修改如下
module.exports = { dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api':{ target:'192.168.1.99:8080/', changeOrigin:true, pathRewrite:{ '^/api':'' } } },
其中主要是加入
proxyTable: { '/api':{ target:'192.168.1.99:8080/', changeOrigin:true, pathRewrite:{ '^/api':'' } } }
这样你通过axios 或fetche访问 /api/** 便相当于跨域访问了 192.168.1.99:8080/
总结
以上所述是小编给大家介绍的Vue开发环境跨域访问问题,希望对大家有所帮助!
本文共计175个文字,预计阅读时间需要1分钟。
Vue开发环境跨域访问其他服务器或本地其他端口,需要在项目中配置config/index.js文件,修改如下:
javascriptmodule.exports={ dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api': { target: 'http://localhost:8080', // 修改为其他服务器的地址和端口 changeOrigin: true, pathRewrite: { '^/api': '' } } } }}
Vue开发环境跨域访问其他服务器或者本机其他端口,需要配置项目中config/index.js文件,修改如下
module.exports = { dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api':{ target:'192.168.1.99:8080/', changeOrigin:true, pathRewrite:{ '^/api':'' } } },
其中主要是加入
proxyTable: { '/api':{ target:'192.168.1.99:8080/', changeOrigin:true, pathRewrite:{ '^/api':'' } } }
这样你通过axios 或fetche访问 /api/** 便相当于跨域访问了 192.168.1.99:8080/
总结
以上所述是小编给大家介绍的Vue开发环境跨域访问问题,希望对大家有所帮助!

