用uniapp开发h5时出现的跨域问题
在manifest.json的源码视图中的h5下进行如下配置,意味着将uni.request发起网络请求时,碰到的/api字符,将转发到tatget的配置的域名
"h5" : {
"title" : "blindDate",
"devServer" : {
"disableHostCheck" : true,
"proxy": {
"/api": {
"target": "https://your.yuming.com",
"changeOrigin": true,
"secure": false,
"pathRewrite":{"^/api":"/"}
}
}
}
}
发起网络请求时将改为
uni.request({
url:"/api/youapiname", //仅为示例,并非真实的接口地址
method: 'POST',
header:{
'content-type': 'application/json', // 默认值
'token': token
},
success(res) {
console.log(res)
}
})