2019-12-02 12:54:32 +08:00
|
|
|
<script src="../../dist/vue.global.js"></script>
|
|
|
|
|
|
|
|
<div id="demo">
|
|
|
|
<h1>Latest Vue.js Commits</h1>
|
|
|
|
<template v-for="branch in branches">
|
|
|
|
<input type="radio"
|
|
|
|
:id="branch"
|
|
|
|
:value="branch"
|
|
|
|
name="branch"
|
|
|
|
v-model="currentBranch">
|
|
|
|
<label :for="branch">{{ branch }}</label>
|
|
|
|
</template>
|
2022-05-12 08:44:57 +08:00
|
|
|
<p>vuejs/core@{{ currentBranch }}</p>
|
2019-12-02 12:54:32 +08:00
|
|
|
<ul>
|
|
|
|
<li v-for="{ html_url, sha, author, commit } in commits">
|
|
|
|
<a :href="html_url" target="_blank" class="commit">{{ sha.slice(0, 7) }}</a>
|
|
|
|
- <span class="message">{{ truncate(commit.message) }}</span><br>
|
|
|
|
by <span class="author"><a :href="author.html_url" target="_blank">{{ commit.author.name }}</a></span>
|
|
|
|
at <span class="date">{{ formatDate(commit.author.date) }}</span>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
2020-02-22 15:19:10 +08:00
|
|
|
const { createApp, ref, watchEffect } = Vue
|
2022-01-18 16:43:59 +08:00
|
|
|
const API_URL = `https://api.github.com/repos/vuejs/core/commits?per_page=3&sha=`
|
2019-12-02 12:54:32 +08:00
|
|
|
|
|
|
|
const truncate = v => {
|
|
|
|
const newline = v.indexOf('\n')
|
|
|
|
return newline > 0 ? v.slice(0, newline) : v
|
|
|
|
}
|
|
|
|
|
|
|
|
const formatDate = v => v.replace(/T|Z/g, ' ')
|
|
|
|
|
2020-01-24 04:05:38 +08:00
|
|
|
createApp({
|
2019-12-02 12:54:32 +08:00
|
|
|
setup() {
|
2022-05-12 08:44:57 +08:00
|
|
|
const currentBranch = ref('main')
|
2019-12-02 12:54:32 +08:00
|
|
|
const commits = ref(null)
|
|
|
|
|
2020-02-22 15:19:10 +08:00
|
|
|
watchEffect(() => {
|
2019-12-11 23:15:52 +08:00
|
|
|
fetch(`${API_URL}${currentBranch.value}`)
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(data => {
|
|
|
|
console.log(data)
|
|
|
|
commits.value = data
|
|
|
|
})
|
2019-12-02 12:54:32 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
return {
|
2022-05-12 08:44:57 +08:00
|
|
|
branches: ['main', 'v2-compat'],
|
2019-12-02 12:54:32 +08:00
|
|
|
currentBranch,
|
|
|
|
commits,
|
|
|
|
truncate,
|
|
|
|
formatDate
|
|
|
|
}
|
|
|
|
}
|
2020-01-24 04:05:38 +08:00
|
|
|
}).mount('#demo')
|
2019-12-02 12:54:32 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
#demo {
|
|
|
|
font-family: 'Helvetica', Arial, sans-serif;
|
|
|
|
}
|
|
|
|
a {
|
|
|
|
text-decoration: none;
|
|
|
|
color: #f66;
|
|
|
|
}
|
|
|
|
li {
|
|
|
|
line-height: 1.5em;
|
|
|
|
margin-bottom: 20px;
|
|
|
|
}
|
|
|
|
.author, .date {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
</style>
|