The micro-channel external js applet to call wx.request方法
upon, because the mechanism for asynchronous requests, we can not on its success:function()
return in the required data directly.
example:
One:
// This method is an external file "utils / util.js" be defined in function REQUEST_METHOD (URL, the callback) { wx.request ({ URL: URL, Method: 'the GET' , header: { 'the Type-the Content': 'file application / JSON' }, Success: function (RES) { the callback && the callback (res.data); } }); }
// need to add to expose this method you define, or can not be found outside the
module. = {Exports
REQUEST_METHOD: REQUEST_METHOD
}
Two corresponding to the current page js method:
// first into the public JS var util = the require ( '../../ utils / util.js' ); util.request_method ( URL, (RES) => { the this .setData ({ otherData: RES }); });