0.0.2-alpha-1 • Published 5 years ago

smart-wx-utils v0.0.2-alpha-1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

smart-wx-utils

提供小程序API及其他通用类型工具函数库,简化开发过程中原生API繁琐的传参及回调形式

计划提供axios式的wx.request工具,提供拦截器支持(计划开发中)

安装

npm install smart-wx-utils

小程序工具库

  1. 小程序API Promise化

    const {wechat} = require('smart-wx-utils')
    
    // 目前2.1.0以下的API完全兼容,后期逐渐同步更新到最新版
    wechat.switchTab({url: '/pages/index'}).then(res => {
        console.log(res)
    })
  2. 小程序API调用传参简化

    const {wechat} = require('smart-wx-utils')
    
    // 和前面的代码等价,更多详情后面逐步更新,也可以看src中的源码
    wechat.switchTab('/pages/index').then(res => {
        console.log(res)
    })
    
    wechat.request('xxxxx', {a: 'b'}, {method: 'GET'}).then(res => {
        console.log(res.data)
    })
  3. 小程序wx.request封装

    const {utils} = require('smart-wx-utils')
    // 默认get
    utils.request.fetch(url, data, ops).then(res=> {
        console.log(res.data)
    })
    // get请求
    utils.request.get(url, data).then(res=> {
        console.log(res.data)
    })
    // post 请求
    utils.request.post(url, data).then(res=> {
        console.log(res.data)
    })