【vue-cli】vue-cli+webpack配置下局域网,手机无法访问绑定ip的vue项目

本文介绍了解决Vue项目在手机浏览器上无法访问的问题的方法,包括配置devServer、检查网络连通性和修改package.json文件等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://192.168.0.104:8080/#/    访问我的vue项目,浏览器可以打开,手机无法打开,在同一局域网段下。

1.设置config文件下的index.js文件:

 dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},

    // Various Dev Server settings
    host: '192.168.0.104', // 也可以设置为0.0.0.0 
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
    
    // Use Eslint Loader?
    // If true, your code will be linted during bundling and
    // linting errors and warnings will be shown in the console.
    useEslint: true,
    // If true, eslint errors and warnings will also be shown in the error overlay
    // in the browser.
    showEslintErrorsInOverlay: false,

    /**
     * Source Maps
     */

    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'cheap-module-eval-source-map',

    // If you have problems debugging vue-files in devtools,
    // set this to false - it *may* help
    // https://vue-loader.vuejs.org/en/options.html#cachebusting
    cacheBusting: true,
    cssSourceMap: true
  },

如果手机还是无法访问,请:

1.电脑cmd ping手机ip,是否能通。

不能通,好吧,那就

1).把防火墙关闭试试

2).手机和电脑要用同一个wifi,然后打开cmd, ipconfig 看下ip是什么,把这个本机的192.168.0.102换掉,端口号仍然需要的,然后在手机端浏览器中输入新的地址

3).关闭路由器的ap隔离

  • 4).电脑弄代理,在手机的wifi里手动把代理服务器的地址设置好

OK,如果还是不能通,那就vue项目里边的package.json打开:

 "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --port 8080 --host 192.168.0.104",

加上粗线的东东,

OK,还不行,翻一翻webpack的配置吧。

附上一个webpack解决此问题的连接:https://github.com/webpack/webpack-dev-server/issues/147




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值