In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to use es6-promise.js to encapsulate requests and handle asynchronous processes", so the editor summarizes the following contents for you. The content is detailed, the steps are clear, and it has certain reference value. I hope you can get something after reading this article. Let's take a look at this article entitled "how WeChat Mini Programs uses es6-promise.js to encapsulate requests and handle asynchronous processes".
WeChat Mini Programs es6-promise.js encapsulates requests and handles asynchronous processes
Download es6-promise.js under the libs folder in the root directory
Create a new httpsPromisify.js under the root directory utils folder, that is, define the method to encapsulate the request
Var Promise = require ('.. / libs/es6-promise.min') function httpsPromisify (fn) {return function (obj = {}) {return new Promise ((resolve, reject) = > {obj.success = function (res) {resolve (res)} obj.fail = function (res) {reject (res)} fn (obj)}} module.exports = {httpsPromisify: httpsPromisify}
Call method:
Var Promisify = require ('.. /.. / utils/httpsPromisify') Page ({onLoad: function () {Promisify.httpsPromisify (wx.request) ({url: "https://XXXXXXX", header: {" Content-Type ":" application/x-www-form-urlencoded "}, method:" POST ", data: {}) .then (function (res) {console.log (res)})} })
Note:
At present, there are many third-party libraries that support promise, such as $q.jsdybluebird.js, etc., but it should be noted that these can be used normally on Wechat development tools, but there is no effect on the real machine; so with es6-Promise.js, this personal test is perfect, and the file size is much smaller than the others, so it is recommended that you use it.
The above is about the content of this article on "how WeChat Mini Programs uses es6-promise.js to encapsulate requests and handle asynchronous processes". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.