本地:http://localhost:3001/
后台:http://localhost:3002/
proxy: {
'/vue-manage': {
target: 'http://localhost:3001/',
changeOrigin: true,
pathRewrite: {
'^/vue-manage': '',
},
},
},
target
:需要代理的后台地址changeOrigin
:決定請求頭中的host屬性值,為true代表本地http://localhost:3001/
,為false代表與后台一致http://localhost:3002/
pathRewrite
:重寫地址,匹配到/vue-manage
后變為空字符串
前端接口統一使用/vue-manage前綴進行處理,當匹配到此前綴時,表示該接口需要進行代理,例如本地/vue-manage/test
會被代理成http://localhost:3002/test