为什么我不能从其他设备通过局域网访问我自己的 Vue Webpack 服务器?

Why can't I access my own Vue Webpack server via LAN from another device?

我在这方面有点陌生,这是我的第一个问题。 我在问你,因为我在 2-3 天内无法解决这个问题,甚至在阅读了很多关于这个问题的 material 之后也没有解决。我发现了什么:

我使用 npmas vue init webpack

初始化我的 vue webpack 项目

完成后,我把host: 'localhost'改成了host: '0.0.0.0',还加了disableHostCheck: true.

config/index.js 开发范围内,我用 -> npm run dev

启动我的服务器

输出:

Compiled successfully in 3070ms                   
Your application is running here: http://0.0.0.0:8080

如果我用 :8080 在浏览器中输入我的 Ipv4 地址,就像 xxx.xxx.xxx.xxx:8080 我的项目就在那里。很好,但我无法从其他设备(例如笔记本电脑或移动设备)看到我的项目 phone。

我不太明白这个,因为我读到如果我们在主机上输入“0.0.0.0”,这意味着每个人都可以访问 LAN 上的项目。

有人能告诉我为什么会这样吗?

我想http://0.0.0.0:8080 available only locally, from machine where your project is running. To see project from another machine (and It should be in the same network it's important) you should obtain your real IP address (you can google how to do it, it depends on OS, on windows use "ipconfig" command in cmd) and then you should see your project in local network on URL which may look like this http://192.168.1.237:8080

好的伙计们,我解决了这个问题。我会写下解决方案,因为当你因为一件你甚至没有想到的小事而无法解决问题时,它既有趣又烦人。

解决方案:只需在该死的 windows 防火墙中启用您的端口 :D

现在我可以在局域网中托管所有内容,public 也可以。

我通过将 Base_url 从 http://localhost:3000 更改为 http://192.168.10.3:3000 解决了这个问题。我的 Express 应用程序和 Vuejs 应用程序都在 IP 地址为 192.168.10.3 的机器上 运行。现在在同一网络的另一台机器上,Vuejs 应用程序是 运行,这应该向机器(IP 192.168.10.3)运行 Expressjs 发送请求。 在命令提示符下使用ipconfig命令,可以确定机器IP。