npm i @nuxtjs/proxy -D
在nuxt.config.js中配置
modules: [
'@nuxtjs/proxy',
],
在nuxt.confo.js中配置 proxy对象
// 数组写法
proxy: [
[
'/api',
{
target: 'http://localhost:3001', // api主机
pathRewrite: { '^/api' : '' }
}
],
[
'/age',
{
target: 'http://localhost:3002', // api主机
// pathRewrite: { '^/api' : '/' }
}
]
],
//对象写法
// proxy: {
// "/name": {
// target: 'http://127.0.0.1:3001'
// },
// '/age': {
// target: 'http://127.0.0.1:3002'
// },
// }