Cause Analysis of vue-cli failure to access the local service LAN
1. Problem description:
The local vue-cli starts a project and can only be accessed through localhost: 8080. Other mobile phones and computers in the same LAN cannot access and debug through IP addresses,
2. cause: the vue-cli project is generated with one click through the command line. The local debugging mode is generated by default in the configuration file, and the default access address is localhost: port number.
3. method of correction
Find the index. js file in the config folder and Modify host: "localhost" TO host: "0.0.0.0". At this time, the mobile phone and other computers in the same LAN can view the page through ip address.
PS: The following figure shows that the webpack project started with vue-cli can be accessed using localhost, but cannot be accessed by switching to an ip address.
I am using a vux Project (Mobile End, based on vue). Because it is a mobile end, I need to test it on the mobile phone and find that http: // localhost: 8081/the access is quite good, but it cannot be accessed by switching to an ip address. At the beginning of this period, I thought it was the reason for proxy. I turned off the computer proxy. Still not good, and then changed to 127.0.0.1 access, found that can access, with 0.0.0.0 access can also be, that is, the ip is not good. Then there will be a variety of google and Baidu. Other people's methods-They tried a lot and found that they were ineffective (a little skeptical about life, maybe my computer problems), but the result is here, ip is not accessible !!!!
In the spirit of a programmer's instinct-Never give up without solving this bug. I started to view my build file and config file. Finally, the root cause is found-the index in config. module in js. change 'localhost' under dev under exports to host: '0. 0.0.0 ', you can access it !!! Then start code happily!
Summary
The above is an analysis of the reason why vue-cli cannot be accessed when the local service LAN is started. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!