为了账号安全,请及时绑定邮箱和手机立即绑定

给Vue封装一个获取后端接口的方法?下面这个代码什么意思?

给Vue封装一个获取后端接口的方法?下面这个代码什么意思?

毛Bing 2018-11-21 15:32:18
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)            })        })    }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1238 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信