Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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();

About

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

Resources

License

Releases

No releases published

Packages

No packages published