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

本文作者:程序员飞云

本站地址:https://www.flycode.icu (opens new window)

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

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"
        }
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

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

# 3. 修改baseurl

export const baseUrl = '/api'
1

# 4. 最终请求地址

http://localhost:8080/api/xxxx
1
最近更新: 1/14/2025, 1:13:36 AM
飞云编程   |