File tree Expand file tree Collapse file tree 2 files changed +86
-0
lines changed Expand file tree Collapse file tree 2 files changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ var apiURL = 'https://api.github.com/repos/yyx990803/vue/commits?per_page=3&sha='
2
+
3
+ var demo = new Vue ( {
4
+
5
+ el : '#demo' ,
6
+
7
+ data : {
8
+ branches : [ 'master' , 'dev' , 'next' ] ,
9
+ currentBranch : 'master' ,
10
+ commits : null
11
+ } ,
12
+
13
+ created : function ( ) {
14
+ this . fetchData ( )
15
+ this . $watch ( 'currentBranch' , function ( ) {
16
+ this . fetchData ( )
17
+ } )
18
+ } ,
19
+
20
+ filters : {
21
+ truncate : function ( v ) {
22
+ var newline = v . indexOf ( '\n' )
23
+ return newline > 0 ? v . slice ( 0 , newline ) : v
24
+ } ,
25
+ formatDate : function ( v ) {
26
+ return v . replace ( / T | Z / g, ' ' )
27
+ }
28
+ } ,
29
+
30
+ methods : {
31
+ fetchData : function ( ) {
32
+ var xhr = new XMLHttpRequest ( )
33
+ var self = this
34
+ xhr . open ( 'GET' , apiURL + self . currentBranch )
35
+ xhr . onload = function ( ) {
36
+ self . commits = JSON . parse ( xhr . responseText )
37
+ }
38
+ xhr . send ( )
39
+ }
40
+ }
41
+ } )
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < title > Vue.js commits example</ title >
5
+ < style >
6
+ # demo {
7
+ font-family : 'Helvetica' , Arial, sans-serif;
8
+ }
9
+ a {
10
+ text-decoration : none;
11
+ color : # f66 ;
12
+ }
13
+ li {
14
+ line-height : 1.5em ;
15
+ margin-bottom : 20px ;
16
+ }
17
+ .author , .date {
18
+ font-weight : bold;
19
+ }
20
+ </ style >
21
+ < script src ="../../dist/vue.js "> </ script >
22
+ </ head >
23
+ < body >
24
+ < div id ="demo ">
25
+ < h1 > Latest Vue.js Commits</ h1 >
26
+ < template v-repeat ="b:branches ">
27
+ < input type ="radio "
28
+ name ="branch "
29
+ id ="{{*b}} "
30
+ value ="{{*b}} "
31
+ v-model ="currentBranch ">
32
+ < label for ="{{*b}} "> {{*b}}</ label >
33
+ </ template >
34
+ < ul >
35
+ < li v-repeat ="commits ">
36
+ < a href ="{{html_url}} " target ="_blank " class ="commit "> {{sha.slice(0, 7)}}</ a >
37
+ - < span class ="message "> {{commit.message | truncate}}</ span > < br >
38
+ by < span class ="author "> {{commit.author.name}}</ span >
39
+ at < span class ="date "> {{commit.author.date | formatDate}}</ span >
40
+ </ li >
41
+ </ ul >
42
+ </ div >
43
+ < script src ="app.js "> </ script >
44
+ </ body >
45
+ </ html >
You can’t perform that action at this time.
0 commit comments