Skip to content

Commit fa1c296

Browse files
committed
add hash change
1 parent 150a0c8 commit fa1c296

File tree

4 files changed

+29
-63
lines changed

4 files changed

+29
-63
lines changed

reactivity/src/App.vue

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,32 @@
11
<template>
22
<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+
228
</div>
239
</template>
2410

2511
<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"
2715
28-
export default {
29-
data: () => ({
30-
branches: ['master', 'sync'],
31-
currentBranch: 'master',
32-
commits: null,
33-
a:1
34-
}),
3516
36-
created() {
37-
this.fetchData()
38-
},
17+
import Hash from "./Hash.js"
3918
40-
watch: {
41-
currentBranch: 'fetchData'
19+
export default {
20+
components: {
21+
LocalStorage, Fragment, HTTPRequest
4222
},
23+
data: () => ({
24+
route: Hash(),
25+
})
4326
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-
}
6027
}
6128
</script>
6229

6330
<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+
7832
</style>

reactivity/src/Hash.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {reactive} from "@vue/reactivity";
2+
3+
4+
export default function HTTPRequest(){
5+
let data = reactive({});
6+
data.value = document.location.hash;
7+
window.addEventListener("hashchange", (v1, v2) => {
8+
data.value = document.location.hash
9+
})
10+
return data;
11+
}

reactivity/src/List.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
let component = {
1010
components: {
11+
1112
},
1213
props: [
1314
"list"

reactivity/src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createApp } from '@vue/runtime-dom';
22
//import { createApp } from './ThreeRender';
33

4-
import App from "./Fragment.vue";
4+
import App from "./App.vue";
55

66
//import "./vanilla-main";
77

0 commit comments

Comments
 (0)