Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

miniprogram-wxios

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

miniprogram-wxios

针对 wx.request 接口进行二次封装。

  • 1.1.1
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

wxios 接口请求

针对 wx.request 接口进行二次封装。

  1. 使用promise调用风格
  2. 加入 拦截器功能

API

  1. wxios(config)

    wxios({
        url: 'http://localhost/api',
        method: 'post',
        data: {
            test: '1'
        }
    }).then(function (response) {
        console.log(response);
    });
    
  2. wxios(url[, config])

    wxios(
        'http://localhost/api',
        {
            method: 'post',
            data: {
                test: '1'
            }
        }
    ).then(function (response) {
        console.log(response);
    });
    
  3. 请求 别名

    1. wxios.request(config)
    2. wxios.get(url, data[, config])
    3. wxios.post(url, data[, config])
    4. wxios.delete(url, data[, config])
    5. wxios.head(url, data[, config])
    6. wxios.put(url, data[, config])
  4. wxios.all(promises)

    var p1 = Promise.resolve();
    var p2 = Promise.resolve();
    wxios.all([p1, p2])
        .then(function(resList){
            console.log(resList);
        });
    
  5. wxios.create([defaultConfig])

    通过 wxios.create([defaultConfig]) 创建一个全新的 wxios实例。

    var instance = wxios.create({
        baseURL: 'http://localhost'
    });
    

    新实例拥有 wxios下挂载的所有request方法。

  6. 请求拦截器

    request拦截器 : wxios.interceptors.request

    // 添加一个拦截器
    // 同时返回一个 拦截器标识
    var interceptorId = wxios.interceptors.request.use(function(config) {
        // do something...
        // TODO:
        // 每个拦截器都必须返回 config
        return config;
    });
    // 删除一个拦截器
    wxios.interceptors.request.eject(interceptorId);
    

    response拦截器 : wxios.interceptors.response

    // 添加一个拦截器
    // 同时返回一个 拦截器标识
    var interceptorId = wxios.interceptors.response.use(function(response) {
        // do something...
        // TODO:
        // 每个拦截器都必须返回 response
        return response;
    });
    // 删除一个拦截器
    wxios.interceptors.response.eject(interceptorId);
    
  7. Default Config

    {
        // 公共接口前缀
        baseURL: '',
        // 公共 headers 配置
        headers: {},
        // 接口超时时间, 单位 ms, 默认为 0,不做超时处理
        timeout: 0
    }
    
    wxios.defaults.baseURL = 'http://localhost';
    wxios.defaults.headers.common['content-type'] = 'application/json';
    wxios.default.headers.post['content-type'] = 'application/json';
    
  8. 取消请求

    wxios.CancelToken

    var cancelToken = wxios.CancelToken.source();
    wxios.post('/test', {}, {
        cancelToken: cancelToken.token
    });
    
    // cancel
    cancelToken.cancel(errorMessage);
    

Keywords

FAQs

Package last updated on 12 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc