我正在try 在8080端口上运行Vue,但无法运行.我刚刚用vue create .
创建了一个全新的项目,用npm run serve
运行它,它在一个随机端口上启动应用程序.
First attempt
运行npm运行服务,无需任何额外配置
$ npm run serve
> vue-demo@0.1.0 serve /Users/ne/projects/vue-demo
> vue-cli-service serve
INFO Starting development server...
Starting type checking service...
Using 1 worker with 2048MB memory limit
98% after emitting CopyPlugin
DONE Compiled successfully in 4294ms 3:21:35 PM
No type errors found
Version: typescript 3.5.3
Time: 4267ms
App running at:
- Local: http://localhost:20415/
- Network: http://192.168.178.192:20415/
Note that the development build is not optimized.
To create a production build, run npm run build.
因此,首先我判断了另一个应用程序是否在该端口上以lsof -i :8080
运行,但没有给出结果.
Second attempt
因此,第二次try 是通过cli强制使用npm run serve -- --port 8080
,这仍然在随机端口上启动应用程序,但在浏览器控制台中没有错误.
Third attempt
接下来,我try 在vue.config.js
中配置应用程序.
module.exports = {
devServer: {
open: process.platform === 'darwin',
host: 'localhost',
port: 8080, // CHANGE YOUR PORT HERE!
https: false,
hotOnly: false,
},
};
这也不起作用,甚至在浏览器控制台中引发异常:
15:25:20.889 :8080/sockjs-node/info?t=1566048320873:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
15:25:20.910 client?81da:172 [WDS] Disconnected!
close @ client?81da:172
15:25:21.982 :8080/sockjs-node/info?t=1566048321978:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
15:25:23.079 :8080/sockjs-node/info?t=1566048323075:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
15:25:25.097 :8080/sockjs-node/info?t=1566048325091:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
15:25:29.151 VM14:1 GET http://localhost:8080/sockjs-node/info?t=1566048329145 net::ERR_CONNECTION_REFUSED
package.json
我加了一个Package.json,因为我可能遗漏了一些东西.
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit"
},
"dependencies": {
"core-js": "^2.6.5",
"vue": "^2.6.10",
"vue-class-component": "^7.0.2",
"vue-property-decorator": "^8.1.0",
"vue-router": "^3.0.3",
"vuex": "^3.0.1"
},
"devDependencies": {
"@types/jest": "^23.1.4",
"@vue/cli-plugin-babel": "^3.10.0",
"@vue/cli-plugin-eslint": "^3.10.0",
"@vue/cli-plugin-typescript": "^3.10.0",
"@vue/cli-plugin-unit-jest": "^3.10.0",
"@vue/cli-service": "^3.10.0",
"@vue/eslint-config-airbnb": "^4.0.0",
"@vue/eslint-config-typescript": "^4.0.0",
"@vue/test-utils": "1.0.0-beta.29",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"node-sass": "^4.9.0",
"sass-loader": "^7.1.0",
"ts-jest": "^23.0.0",
"typescript": "^3.4.3",
"vue-template-compiler": "^2.6.10"
}
}
我错过了什么?