forked from shenghy/VueDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue-resource.html
48 lines (47 loc) · 1.47 KB
/
vue-resource.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="../assets/js/vue.js"></script>
<script src="https://cdn.jsdelivr.net/vue.resource/1.2.1/vue-resource.min.js"></script>
<title>Vue-resource Demo</title>
</head>
<body>
<h1>Vue-resource Demo</h1>
<hr>
<div id="app">
{{message}}
</div>
<script type="text/javascript">
var app=new Vue({
el:'#app',
data:{
message:'hello Vue!'
},
beforeMount:function(){
console.log('Vue挂载之前.');
//get 方式请求
this.$http.get('/example/1.txt').then((response)=>{
//success callback
console.log(response);
this.message=response.body;
},(response)=>{
//error callback
console.log('ajax error!');
});
//Post 方式请求
var formData =new FormData();
formData.append('a','1');
this.$http.post('/example/1.txt',formData).then((response)=>{
//success callback
console.log(response);
this.message=response.body;
},(response)=>{
//error callback
console.log('ajax error!');
});
}
})
</script>
</body>
</html>