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 

},javascript

相關文章
相關標籤/搜索