uni.request cross-domain problem solution

uni.request has a cross-domain problem on the H5 side, and the problem is easy to solve. Just configure manifest.json to solve the problem

If requested url:'https://ditu.58.com/pc/api/sydc/info'

The manifest.json configuration is as follows:

"h5": {
		"devServer": {
			"port": 80,//固定写法
			"disableHostCheck": true,//固定写法
			"proxy": {
				"/pc": {
					"target": "https://ditu.58.com",
					"changeOrigin": true,//固定写法
					"secure": false   //固定写法
				}
			}
		}
	}

uni.request is written as follows:

	uni.request({
					url: '/pc/api/sydc/info',
					dataType:'JSON',
					data:{
						
					},
					success(e) {
					 console.log(e)
					},
					fail(err) {
						console.log(err)
					}
              	})

illustrate:

"port": 80,
"disableHostCheck": true

"changeOrigin": true,
 "secure": false

These four lines are written in a fixed way. "/pc" means that the address starting with "/pc" is automatically added with the "target" field when uni.request requests. Take this example to access the complete url:' https://ditu.58.com/pc/api/sydc/info'

Guess you like

Origin blog.csdn.net/zhtxilyj/article/details/130035866