vue devServer配置问题

前端的请求信息是这样的:

axios.get('/api/hello')
    .then(response => console.log(response.data))

webpac.config.js的配置是这样的:

devServer: {
    proxy: {
        '/api/*': {
            target: 'http:localhost:5000',
        }
    }
}

我想要的是将http://localhost:8080/api/hello的请求发至至http://localhost:5000,但我收到的却是这样的http://localhost:5000/api/hello
我需要怎么配置?
谢谢!

阅读 5.6k
2 个回答

你需要在接口的地方引入这个api

 devServer: {
    proxy: {
      '/api': {
        target: 'http:localhost:5000',
        ws: true,  // proxy websockets 
        changeOrigin: true,  // needed for virtual hosted sites
        pathRewrite: {
          '^/api': ''  // rewrite path
        }
      },
    },
    disableHostCheck: true,
  }

在你的api的的js中引入
const BASEURL = "/api"

推荐问题