|
1 | 1 | <template>
|
2 | 2 | <div id="demo">
|
3 |
| - <h1>Latest Vue.js Commits</h1> |
4 |
| - <input v-model="a" /> |
5 |
| - <template v-for="branch in branches"> |
6 |
| - <input type="radio" |
7 |
| - :id="branch" |
8 |
| - :value="branch" |
9 |
| - name="branch" |
10 |
| - v-model="currentBranch"> |
11 |
| - <label :for="branch">{{ branch }}</label> |
12 |
| - </template> |
13 |
| - <p>vuejs/vue@{{ currentBranch }}</p> |
14 |
| - <ul> |
15 |
| - <li v-for="{ html_url, sha, author, commit } in commits"> |
16 |
| - <a :href="html_url" target="_blank" class="commit">{{ sha.slice(0, 7) }}</a> |
17 |
| - - <span class="message">{{ truncate(commit.message) }}</span><br> |
18 |
| - by <span class="author"><a :href="author.html_url" target="_blank">{{ commit.author.name }}</a></span> |
19 |
| - at <span class="date">{{ formatDate(commit.author.date) }}</span> |
20 |
| - </li> |
21 |
| - </ul> |
| 3 | + {{route.value}} |
| 4 | + <LocalStorage v-if="route.value == '#LocalStorage'"/> |
| 5 | + <Fragment v-if="route.value == '#Fragment'"/> |
| 6 | + <HTTPRequest v-if="route.value == '#HTTPRequest'"/> |
| 7 | + |
22 | 8 | </div>
|
23 | 9 | </template>
|
24 | 10 |
|
25 | 11 | <script>
|
26 |
| -const API_URL = `https://api.github.com/repos/vuejs/vue-next/commits?per_page=3&sha=` |
| 12 | +import LocalStorage from "./LocalStorage.vue" |
| 13 | +import Fragment from "./Fragment.vue" |
| 14 | +import HTTPRequest from "./HTTPRequest.vue" |
27 | 15 |
|
28 |
| -export default { |
29 |
| - data: () => ({ |
30 |
| - branches: ['master', 'sync'], |
31 |
| - currentBranch: 'master', |
32 |
| - commits: null, |
33 |
| - a:1 |
34 |
| - }), |
35 | 16 |
|
36 |
| - created() { |
37 |
| - this.fetchData() |
38 |
| - }, |
| 17 | +import Hash from "./Hash.js" |
39 | 18 |
|
40 |
| - watch: { |
41 |
| - currentBranch: 'fetchData' |
| 19 | +export default { |
| 20 | + components: { |
| 21 | + LocalStorage, Fragment, HTTPRequest |
42 | 22 | },
|
| 23 | + data: () => ({ |
| 24 | + route: Hash(), |
| 25 | + }) |
43 | 26 |
|
44 |
| - methods: { |
45 |
| - fetchData() { |
46 |
| - fetch(`${API_URL}${this.currentBranch}`) |
47 |
| - .then(res => res.json()) |
48 |
| - .then(data => { |
49 |
| - this.commits = data |
50 |
| - }) |
51 |
| - }, |
52 |
| - truncate(v) { |
53 |
| - const newline = v.indexOf('\n') |
54 |
| - return newline > 0 ? v.slice(0, newline) : v |
55 |
| - }, |
56 |
| - formatDate(v) { |
57 |
| - return v.replace(/T|Z/g, ' ') |
58 |
| - } |
59 |
| - } |
60 | 27 | }
|
61 | 28 | </script>
|
62 | 29 |
|
63 | 30 | <style>
|
64 |
| - #demo { |
65 |
| - font-family: 'Helvetica', Arial, sans-serif; |
66 |
| - } |
67 |
| - a { |
68 |
| - text-decoration: none; |
69 |
| - color: #f66; |
70 |
| - } |
71 |
| - li { |
72 |
| - line-height: 1.5em; |
73 |
| - margin-bottom: 20px; |
74 |
| - } |
75 |
| - .author, .date { |
76 |
| - font-weight: bold; |
77 |
| - } |
| 31 | +
|
78 | 32 | </style>
|
0 commit comments