2
0

commits.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <script src="../../dist/vue.min.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 { ref, watchEffect } = Vue
  24. const API_URL = `https://api.github.com/repos/vuejs/vue/commits?per_page=3&sha=`
  25. const truncate = v => {
  26. const newline = v.indexOf('\n')
  27. return newline > 0 ? v.slice(0, newline) : v
  28. }
  29. const formatDate = v => v.replace(/T|Z/g, ' ')
  30. new Vue({
  31. setup() {
  32. const currentBranch = ref('main')
  33. const commits = ref(null)
  34. watchEffect(() => {
  35. fetch(`${API_URL}${currentBranch.value}`)
  36. .then(res => res.json())
  37. .then(data => {
  38. console.log(data)
  39. commits.value = data
  40. })
  41. })
  42. return {
  43. branches: ['main', 'dev'],
  44. currentBranch,
  45. commits,
  46. truncate,
  47. formatDate
  48. }
  49. }
  50. }).$mount('#demo')
  51. </script>
  52. <style>
  53. #demo {
  54. font-family: 'Helvetica', Arial, sans-serif;
  55. }
  56. a {
  57. text-decoration: none;
  58. color: #f66;
  59. }
  60. li {
  61. line-height: 1.5em;
  62. margin-bottom: 20px;
  63. }
  64. .author, .date {
  65. font-weight: bold;
  66. }
  67. </style>