Git Product home page Git Product logo

wx-promise-request's Introduction

wx-promise-request

wx-promise-request 是微信小程序 wx.request 方法的不支持 Promise 和并发数问题的解决方案。如果只需要解决并发数问题,可以使用我的 wx-queue-request

解决问题

  • 支持 Promise (使用 es6-promise 库)。
  • 管理请求队列,解决 request 最大并发数超过 10 会报错的问题。

下载

可以使用 npm 下载

$ npm i wx-promise-request

也可以直接右键保存 index.js 文件。

使用

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)

可以通过 setConfig 配置 wx-promise-request 的行为。

属性 说明 类型 默认值
request 发起网络请求的函数 Function wx.request
Promise Promise 函数 Function es6-promise
concurrency 最大并发数 number 10
import {request, setConfig} from './wx-promise-request';
import qcloud from './vendor/qcloud-weapp-client-sdk/index';
import Promise from 'bluebird';

// 根据自身需求,来定制 request
setConfig({
    request: qcloud.request, // 使用 qcloud 提供的请求方法
    Promise, // 使用 bluebird 作为 Promise
    concurrency: 5, // 限制最大并发数为 5
})

request({
  url: 'test.php',
})
.then(res => console.log(res))
.catch(error => console.log(error));

License

MIT

wx-promise-request's People

Contributors

zhengjunxin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.