vue proxy代理

第一步:定义接口名(根据后台的接口来的)
const proxyApis = [
‘/home’,
‘/wx’,
‘/open’,
‘/file’,
‘/notify’
];
第二步:用vue proxy代理设置
devServer: {
open: process.platform === ‘darwin’,
host: ‘0.0.0.0’,
port: 8080,
https: false,
hotOnly: true,
overlay: {
warnings: true,
errors: true,
},
proxy: (() => {
const proxyObj = {};
proxyApis.forEach(api => {
proxyObj[api] = {
target: proxyTarget,
changeOrigin: true,
};
});
console.log(’/Proxy/’);
console.table(proxyObj);
console.log(’/*************************************************************/’);
return proxyObj;
})(),
before: (app) => {
app.use(’/__open-in-editor’, openInEditor());
},
},
这样就不需要设置每个接口用个api来处理了

你可能感兴趣的:(小技巧,vue)