Home > WeChat Applet > Mini Program Development > Mini program development--wx.request asynchronous encapsulation example tutorial

Mini program development--wx.request asynchronous encapsulation example tutorial

零下一度
Release: 2017-05-24 09:12:00
Original
2224 people have browsed it

This article mainly introduces the relevant information about the asynchronous encapsulation example of the wx.request method of the WeChat applet. Friends in need can refer to

wx-promise-request is a reference to the WeChat applet Asynchronous wrapper of wx.request method.

Solve the problem

Support Promise (using the es6-promise library).

Manage the request queue and solve the problem of error reporting when the maximum number of concurrent requests exceeds 10.

Download

npm install wx-promise-request
Copy after login

and then copy the dist/index.js file to your mini program 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))
Copy after login

API

setConfig(object)

Configure wx-promise-request through setConfig, such as: use qcloud Provided request method; use other Promise libraries, etc.

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));
Copy after login

【Related recommendations】

1. Complete source code download of WeChat mini program

2. WeChat mini program demo: Kaka Auto

3. Simple left swipe operation and waterfall flow layout

The above is the detailed content of Mini program development--wx.request asynchronous encapsulation example tutorial. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template