uni-app跨域请求解决方案

1.官方推荐

cors和插件安装解决跨域

2.配置uni-app 中 manifest.json->h5->devServer

manifest.json

"h5": {
	"devServer": {
		//"port": 8000,
		//"disableHostCheck": true,
		"proxy": {
			"/dpc": {
				"target": "http://127.0.0.1:3000",//目标接口域名
				"changeOrigin": true,//允许跨域
				"secure": false,// 设置支持https协议的代理
				// "pathRewrite":{
				//   "^/dyh":"" //替换为空 自己填写的
				// }
			}
		}
	}
}

http请求

uni.request({
    url: '/api/getUserInfo', 
    success: (res) => {
        console.log(res.data);
    }
});

 

 

你可能感兴趣的:(小程序,uniapp跨域,h5跨域,代理转发)