Vue联系后端
Vue联系后端
config目录下的index.js
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/server':{
target:"http://localhost:8081",
pathRewrite:{"^/server":"/"}
}
},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
//前端端口号
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
按上面配置如果访问http://localhost:8080/server/hhh
实际访问http://localhost:8081/hhh
proxyTable: {
'/server':{
target:"http://localhost:8081",
pathRewrite:{"^/server":"/"}
}
}
/server是匹配的路径
转发到http://localhost:8081上去
pathRewrite:{"^/server":"/"}
重写/server为/