zoukankan      html  css  js  c++  java
  • miniprogramer--ajax

    // api地址
    const api = {
      book: '/todos/10'
    }; 
    
    
    function requestApi(url,params,method,sourceObj){
      if(method == 'POST'){
        var contentType = 'application/x-www-form-urlencoded'
      }else{
        var contentType = 'application/json'
      }
      return new Promise((resolve,reject)=>{
        wx.request({
          url: url,
          method:method,
          data:params,
          header: { 'Content-type': contentType},
          success:function(res){
            // typeof successFun == 'function' && successFun(res.data, sourceObj);
            resolve(res);
            console.log('resolve123456');
          },
          fail:function(res){
            // typeof failFun == 'function' && failFun(res.data,sourceObj)
            reject(res);
          },
          complete:function(res){
            // typeof completeFun == 'function' && completeFun(res.data,sourceObj)
            }
        })
    
      })
    }
    
    module.exports = {
      formatTime: formatTime,
      ajaxMethod: ajaxMethod,
      requestApi,
      api
    }
    
      onShow:function(){
        console.log(app.globalData.webhost+""+utils.api.book)
        utils.requestApi(app.globalData.webhost + "" + utils.api.book, {}, this).then(e => {
          console.log(e, 456789123456789963);
          return new Promise(resolve=>{
            resolve(e);  //继续resolve传递下去
          })
        }).then((r)=>{
          console.log(r,456);
          utils.requestApi('https://jsonplaceholder.typicode.com/todos/1', {}, this).then(w=>{
            console.log(w,456789);
          })
        }).catch(e=>{console.log(e)})
      }
    
    
  • 相关阅读:
    kvm虚拟机添加网卡
    rsync搭建
    hadoop副本数三个变为一个
    nginx日志ip提取参数介绍
    expect使用
    全球语言排行版查询
    mysql忘记密码(跳过权限修改)
    数据备份从阿里云主机(外网主机)拉取到本地服务器
    nginx+keepalived IP飘移(高可用)
    负载均衡配置
  • 原文地址:https://www.cnblogs.com/cyany/p/10083829.html
Copyright © 2011-2022 走看看