vue.config.js中pathRewrite里是什么意思?
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
}
}
用代理首先我们需要一个标识,表明这个连接要使用代理。这里是告诉node,接口用 /api
开头的才使用代理,代理之后的路径为:
http://localhost:3000/api/xxx
这里的pathRewrite就是将’/api'
替换成''
,因为我们要使用的接口路径里没有’/api'