Skip to content

Commit 3f8a3cb

Browse files
committed
update commits example
1 parent f08debd commit 3f8a3cb

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

examples/commits/index.html

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,39 @@
1717
}
1818
</style>
1919

20-
<ul id="demo">
20+
<div id="demo">
2121
<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>
2936

3037
<script src="../../dist/vue.js"></script>
3138
<script>
3239
var demo = new Vue({
40+
3341
el: '#demo',
42+
43+
data: {
44+
branch: 'master'
45+
},
46+
47+
created: function () {
48+
this.$watch('branch', function () {
49+
this.fetchData()
50+
})
51+
},
52+
3453
filters: {
3554
truncate: function (v) {
3655
var newline = v.indexOf('\n')
@@ -40,13 +59,17 @@ <h1>Latest Vue.js Commits</h1>
4059
return v.replace(/T|Z/g, ' ')
4160
}
4261
},
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()
4872
}
49-
xhr.send()
5073
}
5174
})
5275
</script>

0 commit comments

Comments
 (0)