Vue.prototype.$rest = function(api, param = {}, data = {}, ops) {
return new Promise((resolve, reject) => {
let apiArr = apiUrl[api].split(" ");
let url = "";
let method = "get";
if(apiArr.length > 1) {
url = apiArr[1];
method = apiArr[0];
} else {
url = apiUrl[api];
}
let iops = ops ? ops : {
successMessage: '',
disableErrorMsg:false
};
iops.params = param ? param : {};
iops.data = data ? data : {};
iops.url = url;
iops.method = ops && ops.method ? ops.method : method;
this.$api(iops).then(response => {
if(response.success) {
resolve(response);
} else {
if(!iops.disableErrorMsg){
this.alertError(response.error.message);
}
reject(response.error)
}
}).catch(error => {
reject(error)
})
})
}
相关分类