app.js 857 B

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