17
17
}
18
18
</ style >
19
19
20
- < ul id ="demo ">
20
+ < div id ="demo ">
21
21
< h1 > Latest Vue.js Commits</ h1 >
22
- < li v-repeat ="commits ">
23
- < a href ="{{html_url}} " target ="_blank " class ="commit "> {{sha.slice(0, 7)}}</ a >
24
- - < span class ="message "> {{commit.message | truncate}}</ span > < br >
25
- by < span class ="author "> {{commit.author.name}}</ span >
26
- at < span class ="date "> {{commit.author.date | formatDate}}</ span >
27
- </ li >
28
- </ ul >
22
+ < input type ="radio " id ="master " name ="branch " v-model ="branch " value ="master ">
23
+ < label for ="master "> master</ label >
24
+ < br >
25
+ < input type ="radio " id ="dev " name ="branch " v-model ="branch " value ="dev ">
26
+ < label for ="dev "> dev</ label >
27
+ < ul >
28
+ < li v-repeat ="commits ">
29
+ < a href ="{{html_url}} " target ="_blank " class ="commit "> {{sha.slice(0, 7)}}</ a >
30
+ - < span class ="message "> {{commit.message | truncate}}</ span > < br >
31
+ by < span class ="author "> {{commit.author.name}}</ span >
32
+ at < span class ="date "> {{commit.author.date | formatDate}}</ span >
33
+ </ li >
34
+ </ ul >
35
+ </ div >
29
36
30
37
< script src ="../../dist/vue.js "> </ script >
31
38
< script >
32
39
var demo = new Vue ( {
40
+
33
41
el : '#demo' ,
42
+
43
+ data : {
44
+ branch : 'master'
45
+ } ,
46
+
47
+ created : function ( ) {
48
+ this . $watch ( 'branch' , function ( ) {
49
+ this . fetchData ( )
50
+ } )
51
+ } ,
52
+
34
53
filters : {
35
54
truncate : function ( v ) {
36
55
var newline = v . indexOf ( '\n' )
@@ -40,13 +59,17 @@ <h1>Latest Vue.js Commits</h1>
40
59
return v . replace ( / T | Z / g, ' ' )
41
60
}
42
61
} ,
43
- created : function ( ) {
44
- var xhr = new XMLHttpRequest ( )
45
- xhr . open ( 'GET' , 'https://api.github.com/repos/yyx990803/vue/commits?per_page=3' )
46
- xhr . onload = function ( ) {
47
- demo . commits = JSON . parse ( xhr . responseText )
62
+
63
+ methods : {
64
+ fetchData : function ( ) {
65
+ var xhr = new XMLHttpRequest ( ) ,
66
+ self = this
67
+ xhr . open ( 'GET' , 'https://api.github.com/repos/yyx990803/vue/commits?per_page=3&sha=' + self . branch )
68
+ xhr . onload = function ( ) {
69
+ self . commits = JSON . parse ( xhr . responseText )
70
+ }
71
+ xhr . send ( )
48
72
}
49
- xhr . send ( )
50
73
}
51
74
} )
52
75
</ script >
0 commit comments