Skip to content

Commit d224243

Browse files
committed
Example to async title post using skip
1 parent dda2402 commit d224243

File tree

5 files changed

+58
-22
lines changed

5 files changed

+58
-22
lines changed

example/src/App.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<h2>Essential Links</h2>
1111
<nav>
1212
<ul>
13+
<li>
14+
<router-link to="/posts/1" title="Go to post one page" aria-label="Go to example post page">My post</router-link>
15+
</li>
1316
<li>
1417
<router-link to="/about" title="Go to about page" aria-label="Go to about page">About</router-link>
1518
</li>
@@ -20,9 +23,10 @@
2023
</nav>
2124
</header>
2225

23-
<div class="main" role="main">
26+
<main class="main">
27+
<hr>
2428
<router-view />
25-
</div>
29+
</main>
2630
</div>
2731
</template>
2832

@@ -64,4 +68,9 @@ li {
6468
a {
6569
color: #227952;
6670
}
71+
.msg-error {
72+
color: #d4351c;
73+
padding: 10px;
74+
font-weight: bold;
75+
}
6776
</style>

example/src/pages/About.vue

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,16 @@ export default {
2020
name: 'About',
2121
data () {
2222
return {
23-
title: '',
2423
errorMessage: null
2524
}
2625
},
2726
head () {
2827
return {
2928
title: {
30-
inner: this.title
29+
inner: 'About page'
3130
}
3231
}
3332
},
34-
created () {
35-
// get data post in server
36-
setTimeout(() => {
37-
this.title = 'Title of my awesome post'
38-
this.$emit('updateHead')
39-
this.$announcer.set(`${this.title} has loaded`, 'polite') // It's also possible to use the default complementRoute (this.$announcer.options.complementRoute)
40-
}, 2000)
41-
},
4233
methods: {
4334
notify () {
4435
this.errorMessage = 'It\'s error message'
@@ -47,11 +38,3 @@ export default {
4738
}
4839
}
4940
</script>
50-
51-
<style scoped>
52-
.msg-error {
53-
color: #d4351c;
54-
padding: 10px;
55-
font-weight: bold;
56-
}
57-
</style>

example/src/pages/Post.vue

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<template>
2+
<div>
3+
<template v-show="post.id">
4+
<h2>{{ post.title }}</h2>
5+
<p>{{ post.body }}</p>
6+
</template>
7+
<template v-show="error">
8+
<h2 class="msg-error">{{ error }}</h2>
9+
</template>
10+
</div>
11+
</template>
12+
13+
<script>
14+
export default {
15+
name: 'Post',
16+
data () {
17+
return {
18+
post: {},
19+
error: null
20+
}
21+
},
22+
created () {
23+
fetch(`https://jsonplaceholder.typicode.com/posts/${this.$route.params.id}`)
24+
.then(res => {
25+
if (!res.ok) throw Error(res.statusText || 'Error loading the post')
26+
return res.json()
27+
})
28+
.then(res => {
29+
this.post = { ...res }
30+
this.$announcer.set(`${this.post.title} has loaded`)
31+
})
32+
.catch(e => {
33+
this.error = e.message
34+
this.$announcer.set(this.error, 'assertive')
35+
})
36+
}
37+
}
38+
</script>

example/src/router.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import About from '@/pages/About'
22
import Contact from '@/pages/Contact'
33
import Home from '@/pages/Home'
4+
import Post from '@/pages/Post'
45
import Vue from 'vue'
56
import VueRouter from 'vue-router'
67

@@ -23,7 +24,12 @@ const router = new VueRouter({
2324
{
2425
name: 'about',
2526
path: '/about',
26-
component: About,
27+
component: About
28+
},
29+
{
30+
name: 'post',
31+
path: '/posts/:id',
32+
component: Post,
2733
meta: {
2834
announcer: {
2935
skip: true

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function install (Vue, options = {}, router = null) {
4545
const announcer = to.meta.announcer || {}
4646

4747
// Skip: Used, for example, when an async title exists, in which case the announcement is made manually by the set method.
48-
// It is also possible to achieve the same result, using politeness: 'off', but it will be necessary
48+
// It is also possible to achieve the same result, using politeness: 'off', but it will be necessary
4949
// to set the "assertive" or "polite" when using the set method.
5050
// for example: this.$announcer.set('my async title', 'polite')
5151
if (announcer.skip) return

0 commit comments

Comments
 (0)