axios跨域问题

61 阅读1分钟
vue.config.js配置文件,配置代理

方式一:
devServer:{
    proxy:'http://localhost:5000/myBoot'
}
弊端:
    不能控制请求是否代理
    只能代理一个服务器的请求

方式二:
devServer:{
    proxy:{
    '/vue':{ //请求前缀
        target:'http://localhost:5000/myBoot',
        pathRewrite:{'^/vue':''},//发起请求的时候过滤/vue
        changeOrigin:true //true,请求的地址为服务器地址,false时,请求的地址为前端服务器真实地址(默认时true)用于控制请求头中的host值

    },
    '/demo':{
        target:'http://localhost:8080/gogo',
        pathRewrite:{'^/demo':''},
    }
    }
}