无法通过其他设备上的IP地址访问Vue项目vue cli 3 npm [英] Cannot access Vue project by IP address on other devices vue cli 3 npm
问题描述
我有一个使用vue cli 3创建的项目.当我运行命令"npm run serve"时,它会显示以下成功消息(我用伪造的#替换了我的IP地址):
I have a project created with vue cli 3. When I run the command "npm run serve", it gives the following success message (I replaced my IP address with fake #'s):
App running at:
- Local: http://localhost:8080/
- Network: http://1.2.3.4:8080/
我自己的计算机上一切正常.在我自己的计算机上,我既可以通过本地地址访问,也可以通过IP地址访问,但是我无法使用连接到同一wifi网络的其他设备上的网络地址进行访问.
Everything works fine on my own computer. On my own computer I can access both by Local and by IP address, but I cannot access with network address on other devices connected to the same wifi network.
我尝试了以下方法:
On vue.config.js:
devServer: {
host: '0.0.0.0'
}
and
devServer: {
open: process.platform === 'darwin',
host: '0.0.0.0',
port: 8080,
https: false,
hotOnly: false
}
on my package.json:
"scripts": {
"serve": "vue-cli-service serve --host 0.0.0.0",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
}
and
"scripts": {
"serve": "vue-cli-service serve --host 0.0.0.0 --allowed-hosts 1.2.3.4",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
}
我的tomcat服务器运行在端口80上,并且在我的计算机和其他设备上都可以正常工作...我不确定该怎么做...
My tomcat server runs on port 80, and that works fine on both my computer and other devices...I am not sure what else to do...
这是我遇到的错误页面: 如何做到这一点,以便可以从同一网络上的其他设备访问我的vue项目?
This is the error page I run into: How can I make it so that I can access my vue project from other devices on the same network?
感谢您的时间和帮助!
推荐答案
因为您只能访问设备.让我们尝试删除--allowed-hosts 1.2.3.4
Because you only access your device. Lets try remove --allowed-hosts 1.2.3.4
这篇关于无法通过其他设备上的IP地址访问Vue项目vue cli 3 npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!