zoukankan      html  css  js  c++  java
  • ES6 之 Promise

    promise 与ajax

    实现两个ajax返回参数的拼接

    // 函数
    fetch() {
        return new Promise((resolve, reject) => {
         Utils.sendAjax({
          url: 'xxx.html',
          type: 'json',
          callback: function (result) {
            if (result.code == '200') {
              resolve(result.data) // 将返回的data传递给下一个promise
            } else {
              reject()
              Message.warning(result.message)
            }
          }
        })
       })
      }
    
      fetch1(value) {
        return new Promise((resolve, reject) => {
         Utils.sendAjax({
          url: 'xxx.html',
          type: 'json',
          callback: (result) => {
            if (result.code == '200') {
              let data= Object.assign({}, result.data, value)
              this.setState({
                data: data
              })
            } else {
              reject()
              Message.warning(result.message)
            }
          }
        })
       })
      }
    
    //  调用
    
    fetch()
       .then((value) => {
          fetch1(value)
       })
  • 相关阅读:
    日期时间插件
    QQ在线客服
    dede轮播图
    Animation 案例解释
    transition Css3过度详解
    解决文字无法缩小的问题
    DEDE函数
    hdu 3435 图回路分割
    HDU 4183
    hdu 1569 最小割
  • 原文地址:https://www.cnblogs.com/yangstar90/p/6693628.html
Copyright © 2011-2022 走看看