问题描述
我的手机和PC位于同一个wifi中.运行ng serve
时,我可以在PC上使用Chrome在localhost:4200中打开它,
My phone and pc are in same wifi. When I run ng serve
, I open localhost:4200 in Chrome with my PC, which works.
但是我用手机打开192.168.1.107:4200,但无法使用.
But I open 192.168.1.107:4200 with my mobile phone, and it doesn’t work.
当我使用create-react-app
时.有用.
绿色是有角的.白起反应
Green is angular. White is react
推荐答案
为了使您的服务器在本地网络中可用,您需要使用以下命令:
In order to make your server available in local network, you need to use the following command:
ng serve --host 192.168.1.107
然后该应用将在网络中每台设备的192.168.1.107:4200
上可用.
And then the app will be available on 192.168.1.107:4200
on every device in your network.
如果您不知道您的LAN地址是什么,则可以在基于unix的OS上执行ifconfig | grep broadcast
-第一个IP是您的计算机,或者在Windows计算机上是ipconfig
.
If you don't know what is your LAN address you can execute ifconfig | grep broadcast
on unix-based OS - the first IP is your computer, or ipconfig
on Windows machine.
这篇关于如何使用手机打开localhost:4200?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!