美文网首页
promise axios配合使用

promise axios配合使用

作者: 黄黄黄大帅 | 来源:发表于2020-08-07 11:01 被阅读0次
 checkLogin: () => {
// 返回一个promise对象
    return new Promise((resolve, reject) => {
      axios({
            url: url
            method: 'post',
            data: {
            }
          })
            .then((res) => {
              resolve(res.data);
              // console.log(res);
            })
            .catch(function (error) {
              reject(error);
              // console.log(error);
            });
    });
  }

调用

this.common.checkLogin()
              .then(res => {
                console.log(res);
                  // 执行成功的回调函数
              },
              error => { console.log(error); 
              // 执行失败的回调函数
              });
this.common.checkLogin()
      .then(res => {
             console.log(res);
                  // 执行成功的回调函数
        } )
     .catch(e=>{
        console.log(e)
      })

相关文章

网友评论

      本文标题:promise axios配合使用

      本文链接:https://www.haomeiwen.com/subject/mnqfdktx.html