VUE解决跨域的proxyTable中pathRewrite 详解
VUE解决跨域的proxyTable中pathRewrite 详解proxyTable: {'/api':{target:'http://localhost:8083',// secure:true,changeOrigin:true,pathRewrite:{"^/api":""}}}1.要理解pathRewrite,首先要明白proxyTable下‘
·
VUE解决跨域的proxyTable中pathRewrite 详解
proxyTable: {
'/api':{
target:'http://localhost:8083',
// secure:true,
changeOrigin:true,
pathRewrite:{
"^/api":""
}
}
}
1.要理解pathRewrite,首先要明白proxyTable下‘/api’的作用。
使用代理, 首先需要有一个标识, 标明哪些连接需要使用代理,只有有标识的连接才用代理。”/api”就是告知,接口以”/api”开头的才用代理,所以写请求接口时要使用“/api/xx/xx”的形式,使用代理后生成的请求路径就是’http://localhost:8083/api/xx/xx’.
2.pathRewrite中 “^/api”:""的作用
当实际需要请求的路径里面没有”/api“时. 就需要 pathRewrite,用’’^/api’’:’’, 把’/api’去掉, 这样既能有正确标识, 又能在请求到正确的路径。
更多推荐
所有评论(0)