简体   繁体   English

在 vue 项目中执行“npm run serve”命令时不在本地运行

[英]Not running at local when "npm run serve" command in vue project

I was trying to make some app with vue and installed npm command.我试图用 vue 制作一些应用程序并安装 npm 命令。

when I run "npm run serve" command, I get the following messages.当我运行“npm run serve”命令时,我收到以下消息。 It seems that I was supposed to run app at "http://localhost:8080/" and was able to access sample pages, not like "x86_64-apple-darwin13.4.0:" stuff.似乎我应该在“http://localhost:8080/”运行应用程序并且能够访问示例页面,而不是“x86_64-apple-darwin13.4.0:”之类的东西。

is it possible to solve this with changing config file or something?是否可以通过更改配置文件或其他方式解决此问题?

App running at:
  - Local:   http://x86_64-apple-darwin13.4.0:8080/
  - Network: http://x86_64-apple-darwin13.4.0:8080/

  Note that the development build is not optimized.
  To create a production build, run npm run build.

I am supposed to access to http://localhost:8080/ and would get some sample pages.我应该访问 http://localhost:8080/ 并获得一些示例页面。

It seems like your host environment was set to x86_64-apple-darwin13.4.0 , you should be able to set the variable in your bash_profile like this HOST="localhost"似乎您的主机环境设置为x86_64-apple-darwin13.4.0 ,您应该能够像这样在bash_profile中设置变量HOST="localhost"

after that reload the environment with source ~/.bash_profile之后用source ~/.bash_profile重新加载环境

Looks like you can find an answer to your question here - https://forum.vuejs.org/t/npm-run-serve-is-not-defaulting-to-localhost/88007/13 .看起来您可以在这里找到问题的答案 - https://forum.vuejs.org/t/npm-run-serve-is-not-defaulting-to-localhost/88007/13

In a short:简而言之:

  • Add vue.config.js file in a root (same level as package.json file) if you don't have one如果你没有 vue.config.js 文件,请在根目录中添加(与 package.json 文件同一级别)

  • Add the following settings to vue.config.js将以下设置添加到 vue.config.js

module.exports = {
  devServer: {
    host: '127.0.0.1',
    port: 8080,
    public: 'localhost:8080',
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM