uni-app本機應用程序:http://localhost:8080
接口api地址:http://localhost:35949/Test
打開manifest.json配置文件,在"h5"中加入配置:
"h5":{ "devServer":{ "port":8080, //應用程序端口 "disableHostCheck":true, "proxy":{ "/api":{ "target":"http://localhost:35949/", "changeOrigin":true, "secure":false, "pathRewrite":{"^/api":"/"} } } } }
proxy內的配置項表示會將 target內的地址替換為 pathRewrite的值,
配置后請求的方法:
uni.request({
url: 'api/Test',
method: 'POST',
data: {},
success: res => {},
fail: () => {},
complete: () => {}
});
請求的地址會 自動替換為:http://localhost:8080/api/Test
