Vue开发环境跨域访问其他服务器或者本机其他端口,需要配置项目中config/index.js文件,修改如下
module.exports = {
dev: {


// Paths

assetsSubDirectory: 'static',

assetsPublicPath: '/',

proxyTable: {

'/api':{

target:'http://192.168.1.99:8080/',

changeOrigin:true,

pathRewrite:{

'^/api':''

}

}

},
module.exports = {
dev: {


// Paths

assetsSubDirectory: 'static',

assetsPublicPath: '/',

proxyTable: {

'/api':{

target:'http://192.168.1.99:8080/',

changeOrigin:true,

pathRewrite:{

'^/api':''

}

}

},其中主要是加入
proxyTable: {

'/api':{

target:'http://192.168.1.99:8080/',

changeOrigin:true,

pathRewrite:{

'^/api':''

}

}

}
proxyTable: {

'/api':{

target:'http://192.168.1.99:8080/',

changeOrigin:true,

pathRewrite:{

'^/api':''

}

}

}这样你通过axios 或fetche访问
/api/** 便相当于跨域访问了 http://192.168.1.99:8080/http://192.168.1.99:8080/总结总结总结以上所述是小编给大家介绍的Vue开发环境跨域访问问题,希望对大家有所帮助!