vue
项目下 vue.config.js 文件内容添加环境配置
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true, // 是否将依赖包进行转译
devServer: { // 环境配置
proxy: 'http://localhost:3001/', // 配置代理,将请求转发到指定的地址
host: '127.0.0.1', // 指定主机地址
port: '9000', // 指定端口号
open: true // 是否自动打开浏览器
}
})
node
项目下 bin/www 文件下修改 port 端口
var port = normalizePort(process.env.PORT || '3001');
app.set('port', port);
解决端口占用问题
1-打开终端 WIN + R
cmd
2-查看占用端口的进程号
netstat -nao | findstr "3001"
C:\Users\FA>netstat -nao | findstr "3001"
TCP 0.0.0.0:3001 0.0.0.0:0 LISTENING 29400
TCP [::]:3001 [::]:0 LISTENING 29400
3-杀死进程
taskkill -pid 29400 -f
C:\Users\FA>taskkill -pid 29400 -f
成功: 已终止 PID 为 29400 的进程。