app.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* global Vue */
  2. var apiURL = 'https://api.github.com/repos/vuejs/vue/commits?per_page=3&sha='
  3. /**
  4. * Actual demo
  5. */
  6. new Vue({
  7. el: '#demo',
  8. data: {
  9. branches: ['master', 'dev'],
  10. currentBranch: 'master',
  11. commits: null
  12. },
  13. created: function () {
  14. this.fetchData()
  15. },
  16. watch: {
  17. currentBranch: 'fetchData'
  18. },
  19. filters: {
  20. truncate: function (v) {
  21. var newline = v.indexOf('\n')
  22. return newline > 0 ? v.slice(0, newline) : v
  23. },
  24. formatDate: function (v) {
  25. return v.replace(/T|Z/g, ' ')
  26. }
  27. },
  28. methods: {
  29. fetchData: function () {
  30. var self = this
  31. if (navigator.userAgent.indexOf('PhantomJS') > -1) {
  32. // use mocks in e2e to avoid dependency on network / authentication
  33. setTimeout(function () {
  34. self.commits = window.MOCKS[self.currentBranch]
  35. }, 0)
  36. } else {
  37. var xhr = new XMLHttpRequest()
  38. xhr.open('GET', apiURL + self.currentBranch)
  39. xhr.onload = function () {
  40. self.commits = JSON.parse(xhr.responseText)
  41. console.log(self.commits[0].html_url)
  42. }
  43. xhr.send()
  44. }
  45. }
  46. }
  47. })