美文网首页
进一步封装一个axios请求,返回promise对象

进一步封装一个axios请求,返回promise对象

作者: zzyo96 | 来源:发表于2020-03-04 21:22 被阅读0次
    import {postAction} from '@/api/manage'
    import {axios} from '@/utils/request'
    
    export const FormSubmit = {
      data() {
        return {
          btnSubmitDisabled: false
        }
      },
      methods: {
        submitFormHandle(formUrl, params) {
          this.btnSubmitDisabled = true;
          return new Promise((resolve, reject) => {
            postAction(formUrl, params).then((res) => {
              this.btnSubmitDisabled = false;
              resolve(res)
            }, (res) => {
              this.btnSubmitDisabled = false;
              reject(res)
            });
          });
        }
      }
    };
    
    
    //使用的时候
    
    this.submitFormHandle(url,params).then((res)=>{
      console.log(res,'成功')  
    },(res){
      console.log(res,'失败')
    });
    

    相关文章

      网友评论

          本文标题:进一步封装一个axios请求,返回promise对象

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