• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / mxjs-axios / 5657138400

pending completion
5657138400

push

github

twinh
feat(axios): 增加 `onLoadingChange` 选项,在加载前后触发

0 of 12 branches covered (0.0%)

Branch coverage included in aggregate %.

3 of 9 new or added lines in 1 file covered. (33.33%)

5 of 22 relevant lines covered (22.73%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.71
/index.js
1
import axios from 'axios';
2
import $ from 'miaoxing';
3

4
const NOT_FOUND = 404;
4✔
5

6
function showError(error) {
7
  if (error.config && error.config.ignoreError) {
×
8
    return;
×
9
  }
10

11
  $.err(error.response.status === NOT_FOUND ? '很抱歉,您访问的页面不存在,请检查后再试' : '很抱歉,请求出错,请稍后再试');
×
12
}
13

14
const showLoading = (config) => {
4✔
15
  config.loading && $.loading('show');
×
NEW
16
  config.onLoadingChange?.(true);
×
17
};
18

19
const hideLoading = (config) => {
4✔
NEW
20
  config.loading && $.loading('hide');
×
NEW
21
  config.onLoadingChange?.(false);
×
22
};
23

24
axios.interceptors.request.use(config => {
4✔
NEW
25
  showLoading(config);
×
26

27
  const token = window.localStorage.getItem('token');
×
28
  if (token) {
×
29
    config.headers.Authorization = 'Bearer ' + window.localStorage.getItem('token');
×
30
  }
31

32
  return config;
×
33
});
34

35
axios.interceptors.response.use(response => {
4✔
NEW
36
  hideLoading(response.config);
×
37
  return response;
×
38
}, error => {
NEW
39
  hideLoading(error.config);
×
40
  showError(error);
×
41
  return Promise.reject(error);
×
42
});
43

44
export default axios;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc