uniapp local simulator and mobile phone real machine debugging error {"errMsg":"request:fail abort statusCode:-1"} solution

Problem Description:

When developing the project locally with uniapp, there is no exception in h5 rendering. When using the simulator, tablet or mobile phone, an error is reported: {"errMsg":"request:fail abort statusCode:-1"}.

reason:

The simulator, tablet, and mobile phone all have their own independent network environments and cannot directly access the locally built server, so the request will fail.

solve:

Let the simulator, tablet, mobile phone and local server be in the same network environment, specifically

It is available in the simulator: http://10.0.2.2 points to the local server

The tablet and mobile phone must be in the same network environment as the local server. It is best to use the same WIFI, and then configure the request using the IP address.

 

module.exports = {

	
	//#ifdef H5
	HTTP_REQUEST_URL: '/api', //h5正常使用代理访问即可
	//#endif
	
	//#ifdef APP-PLUS
	//HTTP_REQUEST_URL: 'http://192.168.60.13/',  真机、平板使用本地ip来访问
	HTTP_REQUEST_URL: 'http://10.0.2.2/', //模拟器访问本机localhost地址
}

Guess you like

Origin blog.csdn.net/baidu_36095053/article/details/128826866