1. 程式人生 > >vue 配置跨域訪問

vue 配置跨域訪問

class 服務器 gif .cn str ble scrip eap blank

主要在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
}
},

vue 配置跨域訪問