Skip to content

Uniapp小程序转换为h5网页请求后端

约 125 字小于 1 分钟

前端

2025-03-04

本文作者:程序员飞云

本站地址:https://www.flycode.icu

1. 找到对应的mainfest.json的源码视图

image-20241022104129829
image-20241022104129829

2. 配置h5

"h5" : {
        "title" : "sky-take-out-user-mp",
        "devServer" : {
            "disableHostCheck" : true,
            "proxy" : {
                "/api" : {
                    "target" : "http://localhost:9000",
                    "changeOrigin" : true,
                    "pathRewrite" : {
                        "^/api" : ""
                    }
                }
            },
            "https" : false
        },
        "router" : {
            "mode" : "history"
        }
    }

target代理到目标地址,pathRewrite会将/api去除

3. 修改baseurl

export const baseUrl = '/api'

4. 最终请求地址

http://localhost:8080/api/xxxx

贡献者

  • flycodeuflycodeu

公告板

2025-03-04正式迁移知识库到此项目