// vue.config.js,如没有此文件则手动创建 module.exports = { transpileDependencies: ['uview-ui'], // 开发服务器配置 devServer: { port: 8081, // 使用不同端口避免与mobile工程冲突 host: '0.0.0.0', open: true, // 代理配置解决CORS问题 - 与mobile工程保持一致 proxy: { '/api': { target: 'http://localhost:8080', changeOrigin: true, pathRewrite: { '^/api': '', // 移除/api前缀,直接转发到后端 }, onProxyReq: function (proxyReq, req, res) { console.log( '代理请求:', req.method, req.url, '-> http://localhost:8080' + req.url.replace(/^\/api/, ''), ); }, onError: function (err, req, res) { console.error('代理错误:', err); }, }, }, }, };