commits.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/core/commits?per_page=3&sha=`
  24. Vue.createApp({
  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. }).mount('#demo')
  53. </script>
  54. <style>
  55. #demo {
  56. font-family: 'Helvetica', Arial, sans-serif;
  57. }
  58. a {
  59. text-decoration: none;
  60. color: #f66;
  61. }
  62. li {
  63. line-height: 1.5em;
  64. margin-bottom: 20px;
  65. }
  66. .author, .date {
  67. font-weight: bold;
  68. }
  69. </style>