2021-01-28 16:33发布
vue配置反向代理解决跨域问题。
配置:config/index.js中的proxyTable
config/index.js
proxyTable
dev{
proxyTable: {
'/api': {
target: 'http://192.168.0.1:200', // 要代理的域名
changeOrigin: true,//允许跨域
pathRewrite: {
'^/api': '' // 这个是定义要访问的路径,名字随便写
}
使用时:
// /api/getMenu相当于*http://192.168.0.1:200/getMenu
// /api相当于http://192.168.0.1:200
this.$http.get("/api/getMenu", {
.then(res => {
})
.catch(function(error) {
});
最多设置5个标签!
vue配置反向代理解决跨域问题。
配置:
config/index.js
中的proxyTable
dev{
proxyTable: {
'/api': {
target: 'http://192.168.0.1:200', // 要代理的域名
changeOrigin: true,//允许跨域
pathRewrite: {
'^/api': '' // 这个是定义要访问的路径,名字随便写
}
}
}
使用时:
// /api/getMenu相当于*http://192.168.0.1:200/getMenu
// /api相当于http://192.168.0.1:200
this.$http.get("/api/getMenu", {
}
.then(res => {
})
.catch(function(error) {
});
一周热门 更多>