1.1.0 • Published 3 years ago

shc-pc v1.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

shc-pc

NPM version Build Status Coverage Status Known Vulnerabilities changelog license

npm-image

符合接口规范的 HTTP 客户端 - PC

功能

扩展 StandardHttpClient

  • 发送请求前开启 loading(通过 nprogress 实现)
  • 请求结束后关闭 loading
  • 请求出错时给予用户错误提示(通过 element-uiMessage 实现)

http-api-error-tip

示例

import HttpClient from 'shc-pc';

var httpClient = new HttpClient();

httpClient.send({
    url: 'https://httpbin.org/json'
}).then(function([data, response]) {
    console.log('data', data);
});

更多使用方法详见 StandardHttpClient

扩展

  • 如果需要自定义错误提示, 可以继承之后重写 handleError 方法

    import SHC from 'shc-pc';
    
    class HttpClient extends SHC {
        constructor() {
            super({ // 可以在这里传入默认参数
                withCredentials: true,
                timeout: 10 * 1000
            });
        }
    
        handleError(error) {
            super.handleError(error);
    
            if (error._errorCode === 'B1') {
                alert('特殊处理业务错误 B1');
            } else if (error._errorCode === 'B2') {
                alert('特殊处理业务错误 B2');
            }
        }
    }
    
    export default new HttpClient();
1.1.0

3 years ago

1.0.0

3 years ago

1.0.0-beta.0

3 years ago

0.0.6

4 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago