Skip to content

Commit 23c1965

Browse files
feat: added a few edge cases
1 parent 189453f commit 23c1965

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/.vuepress/config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ const sidebar = {
2525
'/guide/component-props',
2626
'/guide/component-custom-events',
2727
'/guide/component-slots',
28-
'/guide/component-provide-inject'
28+
'/guide/component-provide-inject',
29+
'/guide/component-dynamic-async',
30+
'/guide/component-edge-cases'
2931
]
3032
},
3133
{
3234
title: 'Internals',
3335
collapsable: false,
3436
children: [
3537
'/guide/reactivity',
36-
'/guide/component-dynamic-async',
3738
'/guide/optimizations',
3839
'/guide/change-detection'
3940
]

src/guide/component-edge-cases.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Handling Edge Cases
2+
3+
> This page assumes you've already read the [Components Basics](components.md). Read that first if you are new to components.
4+
5+
:::tip Note
6+
All the features on this page document the handling of edge cases, meaning unusual situations that sometimes require bending Vue's rules a little. Note however, that they all have disadvantages or situations where they could be dangerous. These are noted in each case, so keep them in mind when deciding to use each feature.
7+
:::
8+
9+
## Controlling Updates
10+
11+
Thanks to Vue's Reactivity system, it always knows when to update (if you use it correctly). There are edge cases, however, when you might want to force an update, despite the fact that no reactive data has changed. Then there are other cases when you might want to prevent unnecessary updates.
12+
13+
### Forcing an Update
14+
15+
If you find yourself needing to force an update in Vue, in 99.99% of cases, you've made a mistake somewhere For example, you may be relying on state that isn't tracked by Vue's reactivity system, e.g. with `data` property added after component creation.
16+
17+
However, if you've ruled out the above and find yourself in this extremely rare situation of having to manually force an update, you can do so with [`$forceUpdate`](../api/instance-methods.html#forceupdate).
18+
19+
### Cheap Static Components with `v-once`
20+
21+
Rendering plain HTML elements is very fast in Vue, but sometimes you might have a component that contains **a lot** of static content. In these cases, you can ensure that it's only evaluated once and then cached by adding the `v-once` directive to the root element, like this:
22+
23+
``` js
24+
app.component('terms-of-service', {
25+
template: `
26+
<div v-once>
27+
<h1>Terms of Service</h1>
28+
... a lot of static content ...
29+
</div>
30+
`
31+
})
32+
```
33+
34+
:::tip
35+
Once again, try not to overuse this pattern. While convenient in those rare cases when you have to render a lot of static content, it's simply not necessary unless you actually notice slow rendering - plus, it could cause a lot of confusion later. For example, imagine another developer who's not familiar with `v-once` or simply misses it in the template. They might spend hours trying to figure out why the template isn't updating correctly.
36+
:::

0 commit comments

Comments
 (0)