This article mainly introduces the relevant information about the encapsulation example code of the WeChat applet request interface. Friends who need it can refer to
The encapsulation example code of the WeChat applet request interface
Encapsulation of the mini program request interface (essentially calling back the request callback function again)
module.exports.getData = function (url) { var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var method = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'POST'; var header = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }; return new Promise(function (resolve, reject) { wx.request({ url: url, data: data, method: method, header: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, success: function (res) { resolve(res) }, fail: function (res) { reject(res) } }) }) }
Calling method
var common = require("../../common/common.js") common.getData(postUrl) .then(function(data){ this.setData({ //.... }); console.log(data); });
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Introduction to the WeChat Mini Program network request wx.request
Video API in the WeChat Mini Program Parse
The above is the detailed content of Introduction to the encapsulation of the WeChat applet request interface. For more information, please follow other related articles on the PHP Chinese website!