app.js 843 B

123456789101112131415161718192021222324252627282930313233343536
  1. var demo = new Vue({
  2. el: '#demo',
  3. data: {
  4. branch: 'master'
  5. },
  6. created: function () {
  7. this.$watch('branch', function () {
  8. this.fetchData()
  9. })
  10. },
  11. filters: {
  12. truncate: function (v) {
  13. var newline = v.indexOf('\n')
  14. return newline > 0 ? v.slice(0, newline) : v
  15. },
  16. formatDate: function (v) {
  17. return v.replace(/T|Z/g, ' ')
  18. }
  19. },
  20. methods: {
  21. fetchData: function () {
  22. var xhr = new XMLHttpRequest(),
  23. self = this
  24. xhr.open('GET', 'https://api.github.com/repos/yyx990803/vue/commits?per_page=3&sha=' + self.branch)
  25. xhr.onload = function () {
  26. self.commits = JSON.parse(xhr.responseText)
  27. }
  28. xhr.send()
  29. }
  30. }
  31. })