For more information about request import, see this document.
Defects:
Wx. Request a page supports a maximum of 10 wx. requests, and the request sequence cannot be ensured.
For wepy, es6 promise and es7 Asyn and wait are used to ensure synchronous requests.
The usage is the same as that of a applet.
1 request () {2 _ this = This; 3 4 wepy. Request ({5 URL: 'https: // www.madcoder.cn/tests/sleep.php? Time = 1 & t = CSS & C = ', // developer server interface address ", 6 data: 'data', // request parameter", 7 method: 'get', 8 datatype: 'json', // if it is set to JSON, a json request is made to the returned data. parse 9 success: res =>{}, 10 fail: () =>{}, 11 complete: () =>{} 12}); 13 14 },
1 request() { 2 let self = this; 3 let i = 15; 4 let map = [ 5 ‘MA==‘, 6 ‘MQo=‘, 7 ‘Mg==‘, 8 ‘Mw==‘, 9 ‘NA==‘,10 ‘NQ==‘,11 ‘Ng==‘,12 ‘Nw==‘,13 ‘OA==‘,14 ‘OQ==‘,15 ‘YY==‘,16 ‘SS==‘,17 ‘A==‘,18 ‘AD==‘,19 ‘AP==‘20 ];21 while (i--) {22 wepy.request({23 url:24 ‘https://www.madcoder.cn/tests/sleep.php?time=1&t=css&c=‘ +25 map[i] +26 ‘&i=‘ +27 i,28 success(d) {29 self.netrst += d.data + ‘.‘;30 self.$apply();31 }32 });33 }34 },
Wepy-difference from native (request)