axios
拦截器
// Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Do something with response data
return response;
}, function (error) {
// Do something with response error
return Promise.reject(error);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
取消令牌
axios
取消请求有两种方式:
- 可以使用取消令牌取消请求,使用
CancelToken.source
工厂创建取消令牌,如下所示:
const CancelToken = axios.CancelToken;
const source = CancelToken.source(); //取消令牌
axios.get('/user/12345', {
cancelToken: source.token
}).catch(function (thrown) {
if (axios.isCancel(thrown)) {
console.log('Request canceled', thrown.message);
} else {
// handle error
}
});
axios.post('/user/12345', {
name: 'new name'
}, {
cancelToken: source.token
})
// cancel the request (the message parameter is optional)
source.cancel('Operation canceled by the user.');
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- 还可以通过将执行程序函数传递给
CancelToken
构造函数来创建取消令牌:
const CancelToken = axios.CancelToken;
let cancel;
axios.get('/user/12345', {
cancelToken: new CancelToken(function executor(c) {
// An executor function receives a cancel function as a parameter
cancel = c;
})
});
// cancel the request
cancel();
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
注意:您可以使用相同的取消令牌取消多个请求。
vConsole
vConsole:一个轻量、可拓展、针对手机网页的前端开发者调试面板。
<head>
<script src="path/to/vconsole.min.js"></script>
<script>
var vConsole = new VConsole();
</script>
</head>
1
2
3
4
5
6
2
3
4
5
6
js-cookie
js-cookie:一个简单,轻量级的用于处理浏览器cookie的JavaScript API
// 基本
Cookies.set('name', 'value', { expires: 7, path: '' });
Cookies.get('name'); // => 'value'
Cookies.remove('name');
// JSON
Cookies.set('name', { foo: 'bar' });
Cookies.get('name'); // => '{"foo":"bar"}'
Cookies.getJSON('name'); // => { foo: 'bar' }
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
html2canvas
html2canvas:使用JavaScript截图
使用的时候注意查看 Features ,了解支持哪些 CSS 属性。在使用的时候遇到不支持的 CSS 属性,需要尽可能的使用支持的 CSS 属性去替换达到相同的功能。
screenfull.js
screenfull.js:用于跨浏览器使用JavaScript Fullscreen API的简单包装器,可让您将页面或任何元素全屏显示。