app.js 843 B

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