ionic serve 在 localhost 而不是服务器 IP 上启动

ionic serve starts on localhost and not the server IP

当 运行 离子发球时,我看到了这个:

  Gulp startup tasks: [ 'sass', 'watch' ]
  Running dev server: http://localhost:8100
  Running live reload server: http://localhost:35729
  Watching : [ 'www/**/*', '!www/lib/**/*' ]
  Ionic server commands, enter:
    restart or r to restart the client app from the root
    goto or g and a url to have the app navigate to the given url
    consolelogs or c to enable/disable console log output
    serverlogs or s to enable/disable server log output
    quit or q to shutdown the server and exit

这意味着我无法从浏览器访问该应用程序,因为它只侦听本地主机。如何将本地主机更改为实际服务器 IP?

谢谢

ionic address 给出了一个地址列表。 Select其中之一。例如:

Multiple addresses available.
Please select which address to use by entering its number from the list below:
 1) 10.0.0.9 (wlan0)
 2) 172.16.58.1 (vmnet1)
 3) 172.16.16.1 (vmnet8)
 4) localhost
Std in before prompt
Address Selection:

新答案:

对于较新版本的 ionic,这已更改为 --address

  • ionic address 命令提供 select 您的 IP 地址的选项。你可以 select 一个来自。

  • 您可以像这样明确定义 IP 地址和端口:

    ionic serve --address address --port port //8100 is default

    示例 1:ionic serve --address localhost --port 8101

    示例 2:ionic serve --address localhost --port 8101

  • 尝试使用 --lab 选项一次查看多个平台。

    ionic serve --address localhost --lab

点击 Learn more options

旧答案:

使用-address localhost

运行

ionic serve -address localhost

使用 --lab

在多种屏幕尺寸和平台类型上测试您的应用
ionic serve --lab -address localhost