需在工程目錄config/index.js內對proxyTable項進行如下配置:
// config/index.js
module.exports = {
// ...
dev: {
proxyTable: {
// proxy all requests starting with /api to jsonplaceholder
'/api': {
target: 'http://example.com',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}
這樣我們在調用 Api 時,寫 url 只需寫成 /api/lists 就可以代表 example.com/api/lists
官網api截圖
image.png
參考文章
https://blog.csdn.net/ycz19930423/article/details/77326262