You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue中devServer.proxy配置失效:请求仍发往8080端口求助

Vue请求代理配置异常:请求仍发往前端8080端口

我正尝试为Vue应用配置请求代理,以便从独立于前端的服务器接收返回的Cookie。前端运行在8080端口,服务器运行在3000端口,但配置devServer.proxy指向3000端口后,请求仍发往8080端口。

当前使用的vue.config.js配置

module.exports = {
  devServer: {
    proxy: {
      '/api': {
        target: 'https://localhost:3000',
        ws: true,
        changeOrigin: true
      }
    }
  }
}

Axios请求代码

axios.post(`/api/auth/login/`, loginDetails, {
        withCredentials: true, 
        credentials: 'include'
    })
    .then(function (response) {
        console.log('login response: ', response)
    })
    .catch(error => {
        console.error(error)
    });

错误表现

控制台错误显示请求仍发往8080端口:
客户端控制台错误

已尝试的其他配置

曾使用如下配置,且请求URL不带前缀,但问题依旧:

module.exports = {
  devServer: {
    proxy: 'http://localhost:3000'
  }
}

参考了Vue CLI官方的devServer配置文档。


内容的提问来源于stack exchange,提问作者Jeremy Kung

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 03:30:46