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

46 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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