commits.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <script src="../../dist/vue.global.js"></script>
  2. <div id="demo">
  3. <h1>Latest Vue.js Commits</h1>
  4. <template v-for="branch in branches">
  5. <input type="radio"
  6. :id="branch"
  7. :value="branch"
  8. name="branch"
  9. v-model="currentBranch">
  10. <label :for="branch">{{ branch }}</label>
  11. </template>
  12. <p>vuejs/vue@{{ currentBranch }}</p>
  13. <ul>
  14. <li v-for="{ html_url, sha, author, commit } in commits">
  15. <a :href="html_url" target="_blank" class="commit">{{ sha.slice(0, 7) }}</a>
  16. - <span class="message">{{ truncate(commit.message) }}</span><br>
  17. by <span class="author"><a :href="author.html_url" target="_blank">{{ commit.author.name }}</a></span>
  18. at <span class="date">{{ formatDate(commit.author.date) }}</span>
  19. </li>
  20. </ul>
  21. </div>
  22. <script>
  23. const API_URL = `https://api.github.com/repos/vuejs/vue-next/commits?per_page=3&sha=`
  24. const App = {
  25. data: {
  26. branches: ['master', 'sync'],
  27. currentBranch: 'master',
  28. commits: null
  29. },
  30. created() {
  31. this.fetchData()
  32. },
  33. watch: {
  34. currentBranch: 'fetchData'
  35. },
  36. methods: {
  37. fetchData() {
  38. fetch(`${API_URL}${this.currentBranch}`)
  39. .then(res => res.json())
  40. .then(data => {
  41. this.commits = data
  42. })
  43. },
  44. truncate(v) {
  45. const newline = v.indexOf('\n')
  46. return newline > 0 ? v.slice(0, newline) : v
  47. },
  48. formatDate(v) {
  49. return v.replace(/T|Z/g, ' ')
  50. }
  51. }
  52. }
  53. Vue.createApp().mount(App, '#demo')
  54. </script>
  55. <style>
  56. #demo {
  57. font-family: 'Helvetica', Arial, sans-serif;
  58. }
  59. a {
  60. text-decoration: none;
  61. color: #f66;
  62. }
  63. li {
  64. line-height: 1.5em;
  65. margin-bottom: 20px;
  66. }
  67. .author, .date {
  68. font-weight: bold;
  69. }
  70. </style>