一.推荐方法
"scripts": { "serve": "vue-cli-service serve --port 3000", "build": "vue-cli-service build", },
在package.json中的scripts下的serve追加--port 3000
二.npm方法
npm run serve -- --port 3000
在打开本地服务器的时候追加输入
三.追加vue.config.js
module.exports = { devServer: { historyApiFallback: true, port: 3000, noInfo: true, overlay: true }, }
3x4x的vue脚手架配置项目后不会生成vue.config.js,需要自己添加vue.config.js脚本并追加上述描述
四.环境变量$PORT
PORT=3000 npm run serve