vue.config.js
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
devServer: {
proxy: {
'/api': {
// 配置要代理的服务器地址
target: 'http://localhost:8088',
// 如果请求路径中包含 /api 字符串,则将其替换为空
// 例如,访问 /api/user 将会被代理到 http://localhost:8088/user
pathRewrite: { '^/api': '' },
// 是否支持 websocket,默认为 true
ws: true,
// 用于控制请求头中的 host 值
// 如果为 true,代理服务器会将目标地址作为请求的 host
changeOrigin: true,
},
},
},
});