方法1:那就按照字符串来配置
方法2:http-proxy-middleware
插件。
npm install http-proxy-middleware --save
然后在src目录下创建一个setupProxy.js文件。内容如下:
const { createProxyMiddleware } = require('http-proxy-middleware'); module.exports = function (app) { app.use(createProxyMiddleware('/areaapi', { target: 'https://areaapi.fczx.com', changeOrigin: true, pathRewrite: { "^/areaapi": "/" // 把/areaapi 变成空 } })); app.use(createProxyMiddleware('/api', { target: 'https://api.fczx.com', changeOrigin: true, pathRewrite: { "^/api": "/" // 把/api 变成空 } })); };
0.x.x版本的引用方式:
const proxy = require('http-proxy-middleware');