-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxios.html
90 lines (87 loc) · 2.08 KB
/
axios.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>文档标题</title>
<script src="node-modules/vue/dist/vue.js"></script>
<script src="node-modules/axios/dist/axios.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div id="app" class="container">
<h1>Axios</h1>
<a href="javascript:;" class="btn btn-primary" @click="get">Get</a>
<a href="javascript:;" class="btn btn-primary" @click="post">Post</a>
</div>
<script>
new Vue({
el: '#app',
data: {
msg: ''
},
methods: {
get: function () {
axios.get("package.json",{
params: {
userId: "888"
},
headers: {
token: "jack"
}
}).then(res => {
console.log(res.data)
}).catch(function (error) {
console.log(error)
})
},
post : function(){
axios.post("package.json",{
userId: "888"
},
{
headers: {
token: "jack"
}
}).then(res => {
console.log(res.data)
}).catch(function (error) {
console.log(error)
})
},
jsonp : function(){
},
http: function(){
axios({
url: "package.json",
method: "post",
data: {
userId: "888"
},
headers: {
token: "jack"
}
}).then(res => {
console.log(res.data)
}).catch(function (error) {
console.log(error)
})
}
},
mounted: function(){
// 全局拦截器
axios.interceptors.request.use(function(config){
console.log("request init");
return config;
});
axios.interceptors.response.use(function(response){
console.log("response init");
return response;
});
}
})
</script>
</body>
</html>