commits.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 { createApp, ref, watch } = Vue
  24. const API_URL = `https://api.github.com/repos/vuejs/vue-next/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. const App = {
  31. setup() {
  32. const currentBranch = ref('master')
  33. const commits = ref(null)
  34. watch(() => {
  35. fetch(`${API_URL}${currentBranch.value}`)
  36. .then(res => res.json())
  37. .then(data => { commits.value = data })
  38. })
  39. return {
  40. branches: ['master', 'sync'],
  41. currentBranch,
  42. commits,
  43. truncate,
  44. formatDate
  45. }
  46. }
  47. }
  48. createApp().mount(App, '#demo')
  49. </script>
  50. <style>
  51. #demo {
  52. font-family: 'Helvetica', Arial, sans-serif;
  53. }
  54. a {
  55. text-decoration: none;
  56. color: #f66;
  57. }
  58. li {
  59. line-height: 1.5em;
  60. margin-bottom: 20px;
  61. }
  62. .author, .date {
  63. font-weight: bold;
  64. }
  65. </style>