• 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)})
      }
    
    
  • 相关阅读:
    JAVA 线程安全与同步机制
    JAVA 多线程
    el-table 宽度自适应bug
    详解迭代器Iterator
    理解基本类型的溢出
    理解classpath
    I/O(一):基础知识
    C++: 智能指针
    C++: 值类别与移动语义基础
    CUDA 架构与编程概述
  • 原文地址:https://www.cnblogs.com/cyany/p/10083829.html
Copyright © 2020-2023  润新知