Skip to content

Commit 4d5be61

Browse files
committed
Further small docs tweaks
1 parent 7f9d0f1 commit 4d5be61

File tree

4 files changed

+32
-34
lines changed

4 files changed

+32
-34
lines changed

packages/docs/guide/advanced/composition-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The introduction of Vue's [Composition API](https://vuejs.org/guide/extras/compo
99

1010
## Accessing the Router and current Route inside `setup`
1111

12-
Because we don't have access to `this` inside of `setup`, we cannot directly access `this.$router` or `this.$route`. Instead, we use the `useRouter` and `useRoute` functions:
12+
Because we don't have access to `this` inside of `setup`, we cannot directly access `this.$router` or `this.$route`. Instead, we use the `useRouter` and `useRoute` composables:
1313

1414
```vue
1515
<script setup>

packages/docs/guide/advanced/data-fetching.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ const error = ref(null)
4444
// watch the params of the route to fetch the data again
4545
watch(() => route.params.id, fetchData, { immediate: true })
4646
47-
async function fetchData() {
47+
async function fetchData(id) {
4848
error.value = post.value = null
4949
loading.value = true
5050
5151
try {
5252
// replace `getPost` with your data fetching util / API wrapper
53-
post.value = await getPost(route.params.id)
53+
post.value = await getPost(id)
5454
} catch (err) {
5555
error.value = err.toString()
5656
} finally {
@@ -89,22 +89,20 @@ export default {
8989
// watch the params of the route to fetch the data again
9090
this.$watch(
9191
() => this.$route.params.id,
92-
() => {
93-
this.fetchData()
94-
},
92+
this.fetchData,
9593
// fetch the data when the view is created and the data is
9694
// already being observed
9795
{ immediate: true }
9896
)
9997
},
10098
methods: {
101-
async fetchData() {
99+
async fetchData(id) {
102100
this.error = this.post = null
103101
this.loading = true
104102
105103
try {
106104
// replace `getPost` with your data fetching util / API wrapper
107-
this.post = await getPost(this.$route.params.id)
105+
this.post = await getPost(id)
108106
} catch (err) {
109107
this.error = err.toString()
110108
} finally {

packages/docs/guide/advanced/extending-router-link.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,6 @@ Let's extend RouterLink to handle external links as well and adding a custom `in
1212
::: code-group
1313

1414
```vue [Composition API]
15-
<template>
16-
<a v-if="isExternalLink" v-bind="$attrs" :href="to" target="_blank">
17-
<slot />
18-
</a>
19-
<router-link
20-
v-else
21-
v-bind="$props"
22-
custom
23-
v-slot="{ isActive, href, navigate }"
24-
>
25-
<a
26-
v-bind="$attrs"
27-
:href="href"
28-
@click="navigate"
29-
:class="isActive ? activeClass : inactiveClass"
30-
>
31-
<slot />
32-
</a>
33-
</router-link>
34-
</template>
35-
3615
<script setup>
3716
import { computed } from 'vue'
3817
import { RouterLink } from 'vue-router'
@@ -51,9 +30,7 @@ const isExternalLink = computed(() => {
5130
return typeof props.to === 'string' && props.to.startsWith('http')
5231
})
5332
</script>
54-
```
5533
56-
```vue [Options API]
5734
<template>
5835
<a v-if="isExternalLink" v-bind="$attrs" :href="to" target="_blank">
5936
<slot />
@@ -74,7 +51,9 @@ const isExternalLink = computed(() => {
7451
</a>
7552
</router-link>
7653
</template>
54+
```
7755

56+
```vue [Options API]
7857
<script>
7958
import { RouterLink } from 'vue-router'
8059
@@ -95,6 +74,27 @@ export default {
9574
},
9675
}
9776
</script>
77+
78+
<template>
79+
<a v-if="isExternalLink" v-bind="$attrs" :href="to" target="_blank">
80+
<slot />
81+
</a>
82+
<router-link
83+
v-else
84+
v-bind="$props"
85+
custom
86+
v-slot="{ isActive, href, navigate }"
87+
>
88+
<a
89+
v-bind="$attrs"
90+
:href="href"
91+
@click="navigate"
92+
:class="isActive ? activeClass : inactiveClass"
93+
>
94+
<slot />
95+
</a>
96+
</router-link>
97+
</template>
9898
```
9999

100100
:::

packages/docs/guide/essentials/dynamic-matching.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import { useRoute } from 'vue-router'
6969
7070
const route = useRoute()
7171
72-
watch(() => route.params, (newParams, previousParams) => {
72+
watch(() => route.params.id, (newId, oldId) => {
7373
// react to route changes...
7474
})
7575
</script>
@@ -80,8 +80,8 @@ watch(() => route.params, (newParams, previousParams) => {
8080
export default {
8181
created() {
8282
this.$watch(
83-
() => this.$route.params,
84-
(toParams, previousParams) => {
83+
() => this.$route.params.id,
84+
(newId, oldId) => {
8585
// react to route changes...
8686
}
8787
)

0 commit comments

Comments
 (0)