uni-appH5跨域请求解决⽅案uni-app本机应⽤程序:localhost:8080
接⼝api地址:localhost:35949/Test
打开manifest.json配置⽂件,最底部点击"源码视图",在"h5"中加⼊配置,
prot为前端应的端⼝,taget为后端服务的地址+端⼝
"h5":{
"devServer":{
h5平台源码下载"port":8080, //应⽤程序端⼝
"disableHostCheck":true,
"proxy":{
"/api":{
"target":"localhost:35949/", //后端服务端⼝
"changeOrigin":true,
"secure":false,
"pathRewrite":{"^/api":"/"}
}
}
}
}
proxy内的配置项表⽰会将 target内的地址替换为 pathRewrite的值,
配置后请求的⽅法:
url: 'api/Test',
method: 'POST',
data: {},
success: res => {},
fail: () => {},
complete: () => {}
});
  请求的地址会⾃动替换为:localhost:8080/api/Test