Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

为什么请求要用ip而不是localhost

在我服务器上
我开启后端代码
当我前端通过localhost:xx也能请求得到数据,为啥要在前端代码判断当前环境,生产环境用ip呢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

localhost 可以简单看成 127.0.0.1,如果前端代码部署在当前机器上,那就没事,但如果在另一台呢?两者之间的通信就得通过本机 ip 来,建议参考这篇文章:https://blog.csdn.net/xifeiji...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...