背景

当我们启动了前端开发服务之后,一般使用http://localhost:{port}来访问系统。那么,localhost服务只能被本机访问,即便是同在一个局域网的手机也无法访问

那么,我们想通过手机访问前端开发服务,从而进行真机调试,该怎么做呢?

方案

只需在文件{project}/build/config.js中修改以下配置即可:

  1. 1// front
  2. 2const front = {
  3. 3 dev: {
  4. 4 // hostname: 'localhost',
  5. 5 hostname: '192.168.0.100',
  6. 6 port: 9192,
  7. 7 // proxyBaseURL: 'http://localhost:7002',
  8. 8 },
  9. 9};

比如,前端开发PC的IP地址是192.168.0.100,那么将front.dev.hostname设置为该值,然后启动前端开发服务,那么手机端就可以通过如下地址访问系统:http://192.168.0.100:9192