需在工程目录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截图

参考文章
https://blog.csdn.net/ycz19930423/article/details/77326262
网友评论