进一步封装一个axios请求,返回promise对象
2020-03-04 本文已影响0人
zzyo96
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,'失败')
});