2020-08-27 17:18:57 +08:00

1.4 KiB
Raw Blame History

接口调用 FesApi

对vue-resource的封装。公共的异常处理响应处理等。

函数

  • get(url, data, option)
    发起一个get请求返回值是promise对象
     this.FesApi.get("/query").then(rst=>{})
  • post(url, data, option)
    发起一个post请求返回值是promise对象
     this.FesApi.post("/query").then(rst=>{})
  • fetch(url, data, option)
    默认调用post请求返回值是promise对象
     this.FesApi.fetch("/query").then(rst=>{})
  • option(option)
    设置ajax的公共配置比如root根路径、timeout超时时间、xhrxhr对象
     this.FesApi.option({
          root: "http://l.sit.webank.io/pmbank-wpadm/product"
      });
  • setError(errors)
    设置当响应状态是非200时触发的事件钩子比如401啊等
     this.FesApi.setError({
        200: function(){
            alert(200)
        }
     })
  • setResponse(constructionOfResponse)
    设置响应结构。响应一般会由状态码、错误消息、数据组成。通过此函数设置一个路径,当响应回来是来解析响应。 promise的第一个参数是解析resultPath拿到的值
     //设置响应结构
     this.FesApi.setResponse({
         successCode : "0",
         codePath : "code",
         messagePath : "msg",
         resultPath : "result"
     });