zoukankan      html  css  js  c++  java
  • 微信小程序api封装(promise)

    顺带这是我平时公司切换改变网络环境

    直接上代码,我相信就可以懂了,

    //app.js
    function fetchApi(url, type, params, method) {
        return new Promise((resolve, reject) => {
            wx.request({
                url: `${url}/${type}`,
                data: params,
                method: method,
                header: {
                    'content-type': 'application/x-www-form-urlencoded'
                },
                success: resolve,
                fail: reject
            })
        })
    }
    
    module.exports = {
        // 登录
        GetLogin: function(params) {
            return fetchApi(url1, 'wx/login.html', params, 'POST')
                .then(res => res.data)
        },
    }
    
    
    // login.js
      var api = require('../../utils/api.js'); //引入api.js页面
      
      nextClick: function() {
        var params = {
          dataFrom: xxx,
          code: xxx,
          identity: xxx,
          username: xxx,
          password: xxx,
        }
        api.GetLogin(params)
        .then(res => {
          //你要执行的代码
        })
      }
  • 相关阅读:
    MySQL库表设计小技巧
    教你用SQL实现统计排名
    Truncate用法详解
    utf8字符集下的比较规则
    关于Aborted connection告警日志的分析
    MySQL DDL详情揭露
    时间戳,这样用就对了
    在线修改主从复制选项
    20181211HW
    20181207hw
  • 原文地址:https://www.cnblogs.com/mei1234/p/9965232.html
Copyright © 2011-2022 走看看