手机局域网内访问PC开发中的页面

105 阅读1分钟

首先检查PC与手机是否ping通

截屏2023-11-28 11.05.44.png

截屏2023-11-28 11.17.07.png

IP地址:192.168.31.99(电脑)

IP地址:192.168.31.48(手机)

路由器:192.168.31.1

网关:192.168.31.255

能ping通

然后,检查pc端是否可ip访问

http://localhost:5173 访问成功

http://192.168.31.99:5173 访问成功

即可在手机端用ip访问开发页面

若不成功,在server配置中配置host,例如vite中配置

server: {
    port: 5174,
    host: '0.0.0.0', // 解决ip访问问题
    proxy: {// 解决跨域问题
      '/oauth': { // 认证
        target: 'https://dev-mall.xxx.com/api/',
        changeOrigin: true,
        secure: false,
      },
      '/mall': { // 商城
        target: 'https://dev-mall.xxx.com/api/',
        changeOrigin: true,
        secure: false,
      },
      '/vip': { // 会员卡
        target: 'https://dev-mall.xxx.com/api/',
        changeOrigin: true,
        secure: false,
      },
      '/apiweb': { // 通联支付
        target: 'https://syb.allinpay.com',
        // target: 'https://syb-test.allinpay.com',
        changeOrigin: true,
        secure: false,
      },
    },
  },