vue 配置跨域访问

主要在config->index.js中配置 
proxyTable: { 
‘/gameapi’: { 
changeOrigin: true, 
// target: ‘http://rap.id.cn/mockjs/20‘, mock地址 
target: ‘http://192.168.1.124‘,服务器地址 
pathRewrite: { 
‘^/gameapi’: ‘/gameapi’ 
}, 
secure:false 


因此,发送请求时候url写为(’/gameapi/gift-applylist’)就能拿到接口数据。 
但是注意配置后需要重新npm run dev才会生效。 
当然如果有两个不同路径也可以配置两个 
proxyTable: { 
‘/gameapi’: { 
changeOrigin: true, 
// target: ‘http://rap.id.cn/mockjs/20‘, 
target: ‘http://192.168.1.124‘, 
pathRewrite: { 
‘^/gameapi’: ‘/gameapi’ 
}, 
secure:false 
}, 
‘/cps’: { 
changeOrigin: true, 
// target: ‘http://rap.idu.cn/mockjs/20‘, 
target: ‘http://192.168.1.124‘, 
pathRewrite: { 
‘^/cps’: ‘/cps’ 
}, 
secure:false 

},

原文地址:https://www.cnblogs.com/jackking/p/7422322.html