Examples of asynchronous encapsulation of the applet wx. request method are described in detail, and the applet wx. request
Wx-promise-request is an asynchronous encapsulation of the applet wx. request Method.
Solve the problem
Support Promise (using the es6-promise library ).
Manage request queues to solve the problem that an error is reported if the maximum number of requests is greater than 10.
Download
npm install wx-promise-request
Copy the dist/index. js file to your applet project.
Use
import {request} from './wx-promise-request';request({ url: 'test.php', data: { x: '', y: '', }, header: { 'content-type': 'application/json', },}).then(res => console.log(res)).catch(error => console.error(error))
API
SetConfig (object)
Configure wx-promise-request through setConfig, such as using the request method provided by qcloud and using other Promise libraries.
import {request, setConfig} from './wx-promise-request';import qcloud from './vendor/qcloud-weapp-client-sdk/index';import Promise from 'bluebird';setConfig({ request: qcloud.request, Promise,})request({ url: 'test.php',}).then(res => console.log(res)).catch(error => console.log(error));
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!