vue3-yuanma/packages/vue/examples/classic/commits.html
Evan You c07751fd36 refactor: adjust createApp related API signatures
BREAKING CHANGE: `createApp` API has been adjusted.

  - `createApp()` now accepts the root component, and optionally a props
  object to pass to the root component.
  - `app.mount()` now accepts a single argument (the root container)
  - `app.unmount()` no longer requires arguments.

  New behavior looks like the following:

  ``` js
  const app = createApp(RootComponent)
  app.mount('#app')
  app.unmount()
  ```
2020-01-27 16:00:17 -05:00

77 lines
1.7 KiB
HTML

<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>
<p>vuejs/vue@{{ currentBranch }}</p>
<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>
const API_URL = `https://api.github.com/repos/vuejs/vue-next/commits?per_page=3&sha=`
Vue.createApp({
data: () => ({
branches: ['master', 'sync'],
currentBranch: 'master',
commits: null
}),
created() {
this.fetchData()
},
watch: {
currentBranch: 'fetchData'
},
methods: {
fetchData() {
fetch(`${API_URL}${this.currentBranch}`)
.then(res => res.json())
.then(data => {
this.commits = data
})
},
truncate(v) {
const newline = v.indexOf('\n')
return newline > 0 ? v.slice(0, newline) : v
},
formatDate(v) {
return v.replace(/T|Z/g, ' ')
}
}
}).mount('#demo')
</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>