You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/best-practices/performance.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -51,15 +51,15 @@ One of the most effective ways to improve page load performance is shipping smal
51
51
52
52
- Be cautious of size when introducing new dependencies! In real world applications, bloated bundles are most often a result of introducing heavy dependencies without realizing it.
53
53
54
-
- If using a build step, prefer dependencies that offer ES module formats and are tree-shaking-friendly. For example, prefer `lodash-es` over `lodash`.
54
+
- If using a build step, prefer dependencies that offer ES module formats and are tree-shakingfriendly. For example, prefer `lodash-es` over `lodash`.
55
55
56
-
- Check a dependency's size and evaluate whether it is worth the functionality it provides. Note if the dependency is tree-shaking-friendly, the actual size increase will depend on the APIs you actually import from it. Tools like [bundle.js.org](https://bundle.js.org/) can be used for quick checks, but measuring with your actual build setup will always be the most accurate.
56
+
- Check a dependency's size and evaluate whether it is worth the functionality it provides. Note if the dependency is tree-shakingfriendly, the actual size increase will depend on the APIs you actually import from it. Tools like [bundle.js.org](https://bundle.js.org/) can be used for quick checks, but measuring with your actual build setup will always be the most accurate.
57
57
58
58
- If you are using Vue primarily for progressive enhancement and prefer to avoid a build step, consider using [petite-vue](https://github.com/vuejs/petite-vue) (only **6kb**) instead.
59
59
60
60
### Code Splitting
61
61
62
-
Code splitting stands for the build tool splitting the application bundle into multiple smaller chunks which can then be loaded on demand or in parallel. With proper code splitting, features required at page load can be downloaded immediately, with additional chunks being lazy loaded only when needed, thus improving performance.
62
+
Code splitting is where a build tool splits the application bundle into multiple smaller chunks, which can then be loaded on demand or in parallel. With proper code splitting, features required at page load can be downloaded immediately, with additional chunks being lazy loaded only when needed, thus improving performance.
63
63
64
64
Bundlers like Rollup (which Vite is based upon) or webpack can automatically create split chunks by detecting the ESM dynamic import syntax:
65
65
@@ -116,19 +116,19 @@ Now, for most components the `active` prop will remain the same when `activeId`
116
116
117
117
### `v-once`
118
118
119
-
`v-once` is a built-in directive that can be used to render content that relies on runtime data but never needs to update. The entire subtree it is used on will be skipped for all future updates. Consult its [API reference](/api/built-in-directives.html#v-once) for more details.
119
+
`v-once` is a built-in directive that can be used to render content that relies on runtime data but never needs to update. The entire sub-tree it is used on will be skipped for all future updates. Consult its [API reference](/api/built-in-directives.html#v-once) for more details.
120
120
121
121
### `v-memo`
122
122
123
-
`v-memo` is a built-in directive that can be used to conditionally skip the update of large subtrees or `v-for` lists. Consult its [API reference](/api/built-in-directives.html#v-memo) for more details.
123
+
`v-memo` is a built-in directive that can be used to conditionally skip the update of large sub-trees or `v-for` lists. Consult its [API reference](/api/built-in-directives.html#v-memo) for more details.
124
124
125
125
## General Optimizations
126
126
127
127
> The following tips affect both page load and update performance.
128
128
129
129
### Virtualize Large Lists
130
130
131
-
One of the most common performance issues in all frontend applications is rendering large lists. No matter how performant a framework is, rendering a list with thousands of items **will** be slow due to the sheer amount of DOM nodes that the browser needs to handle.
131
+
One of the most common performance issues in all frontend applications is rendering large lists. No matter how performant a framework is, rendering a list with thousands of items **will** be slow due to the sheer number of DOM nodes that the browser needs to handle.
132
132
133
133
However, we don't necessarily have to render all these nodes upfront. In most cases, the user's screen size can display only a small subset of our large list. We can greatly improve the performance with **list virtualization**, the technique of only rendering the items that are currently in or close to the viewport in a large list.
134
134
@@ -139,7 +139,7 @@ Implementing list virtualization isn't easy, luckily there are existing communit
139
139
140
140
### Reduce Reactivity Overhead for Large Immutable Structures
141
141
142
-
Vue's reactivity system is deep by default. While this makes state management intuitive, it does create a certain level of overhead when the data size is large, because every property access triggers proxy traps that performs dependency tracking. This typically becomes noticeable when dealing with large arrays of deeply nested objects, where a single render needs to access 100,000+ properties, so it should only affect very specific use cases.
142
+
Vue's reactivity system is deep by default. While this makes state management intuitive, it does create a certain level of overhead when the data size is large, because every property access triggers proxy traps that perform dependency tracking. This typically becomes noticeable when dealing with large arrays of deeply nested objects, where a single render needs to access 100,000+ properties, so it should only affect very specific use cases.
143
143
144
144
Vue does provide an escape hatch to opt-out of deep reactivity by using [`shallowRef()`](/api/reactivity-advanced.html#shallowref) and [`shallowReactive()`](/api/reactivity-advanced.html#shallowreactive). Shallow APIs create state that is reactive only at the root level, and exposes all nested objects untouched. This keeps nested property access fast, with the trade-off being that we must now treat all nested objects as immutable, and updates can only be triggered by replacing the root state:
Copy file name to clipboardExpand all lines: src/guide/built-ins/keep-alive.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ By default, `<KeepAlive>` will cache any component instance inside. We can custo
71
71
</KeepAlive>
72
72
```
73
73
74
-
The match is checked against the component's [`name`](/api/options-misc.html#name) option, so components that need to be conditionally cached by `KeepAlive` must explicitly delcare a `name` option.
74
+
The match is checked against the component's [`name`](/api/options-misc.html#name) option, so components that need to be conditionally cached by `KeepAlive` must explicitly declare a `name` option.
75
75
76
76
## Max Cached Instances
77
77
@@ -85,7 +85,7 @@ We can limit the maximum number of component instances that can be cached via th
85
85
86
86
## Lifecycle of Cached Instance
87
87
88
-
When a component instance is removed from the DOM but is part of a component tree cached by `<KeepAlive>`, it goes into **deactivated** state instead of unmounted. When a component instance is inserted into the DOM as part of a cached tree, it is **activated**.
88
+
When a component instance is removed from the DOM but is part of a component tree cached by `<KeepAlive>`, it goes into a **deactivated** state instead of being unmounted. When a component instance is inserted into the DOM as part of a cached tree, it is **activated**.
89
89
90
90
<divclass="composition-api">
91
91
@@ -110,7 +110,7 @@ onDeactivated(() => {
110
110
</div>
111
111
<divclass="options-api">
112
112
113
-
A kept-alive component can register lifecycle hooks for these two states using [`activated`](/api/options-lifecycle.html#activated) and [`deactovated`](/api/options-lifecycle.html#deactivated) hooks:
113
+
A kept-alive component can register lifecycle hooks for these two states using [`activated`](/api/options-lifecycle.html#activated) and [`deactivated`](/api/options-lifecycle.html#deactivated) hooks:
@@ -85,17 +85,17 @@ The `<Suspense>` component has two slots: `#default` and `#fallback`. Both slots
85
85
</Suspense>
86
86
```
87
87
88
-
On initial render, `<Suspense>` will render its default slot content in memory. If any async dependencies are encountered during the process, it will enter **pending** state. During pending state, the fallback content will be displayed. When all encountered async dependencies have been resolved, `<Suspense>` enters **resolved** state and the resolved default slot content is displayed.
88
+
On initial render, `<Suspense>` will render its default slot content in memory. If any async dependencies are encountered during the process, it will enter a **pending** state. During the pending state, the fallback content will be displayed. When all encountered async dependencies have been resolved, `<Suspense>` enters a**resolved** state and the resolved default slot content is displayed.
89
89
90
-
If no async dependencies were encountered during the initial render, `<Suspense>` will directly go into resolved state.
90
+
If no async dependencies were encountered during the initial render, `<Suspense>` will directly go into a resolved state.
91
91
92
-
Once in resolved state, `<Suspense>` will only revert to pending state if the root node of the `#default` slot is replaced. New async dependencies nested deeper in the tree will **not** cause the `<Suspense>` to revert into pending state.
92
+
Once in a resolved state, `<Suspense>` will only revert to a pending state if the root node of the `#default` slot is replaced. New async dependencies nested deeper in the tree will **not** cause the `<Suspense>` to revert to a pending state.
93
93
94
94
When a revert happens, fallback content will not be immediately displayed. Instead, `<Suspense>` will display the previous `#default` content while waiting for the new content and its async dependencies to be resolved. This behavior can be configured with the `timeout` prop: `<Suspense>` will switch to fallback content if it takes longer than `timeout` to render the new default content. A `timeout` value of `0` will cause the fallback content to be displayed immediately when default content is replaced.
95
95
96
96
## Events
97
97
98
-
In addition to the `pending` event, the `<suspense>` component also has `resolve` and `fallback` events. The `resolve` event is emitted when new content has finished resolving in the `default` slot. The `fallback` event is fired when the contents of the `fallback` slot are shown.
98
+
The `<Suspense>` component emits 3 events: `pending`, `resolve` and `fallback`. The `pending` event occurs when entering a pending state. The `resolve` event is emitted when new content has finished resolving in the `default` slot. The `fallback` event is fired when the contents of the `fallback` slot are shown.
99
99
100
100
The events could be used, for example, to show a loading indicator in front of the old DOM while new components are loading.
Copy file name to clipboardExpand all lines: src/guide/built-ins/teleport.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ When using this component inside the initial HTML structure, there are a number
111
111
112
112
The `to` target of `<Teleport>` expects a CSS selector string or an actual DOM node. Here, we are essentially telling Vue to "**teleport** this template fragment **to** the **`body`** tag".
113
113
114
-
You can click the button below and inspect the `<body>` tag via browser devtools:
114
+
You can click the button below and inspect the `<body>` tag via your browser's devtools:
115
115
116
116
<scriptsetup>
117
117
let open =$ref(false)
@@ -170,7 +170,7 @@ Where the `isMobile` state can be dynamically updated by detecting media query c
170
170
171
171
## Multiple Teleports on the Same Target
172
172
173
-
A common use case scenario would be a reusable `<Modal>` component of which there might be multiple instances active at the same time. For this kind of scenario, multiple `<Teleport>` components can mount their content to the same target element. The order will be a simple append - later mounts will be located after earlier ones within the target element.
173
+
A common use case would be a reusable `<Modal>` component, with the potential for multiple instances to be active at the same time. For this kind of scenario, multiple `<Teleport>` components can mount their content to the same target element. The order will be a simple append - later mounts will be located after earlier ones within the target element.
Copy file name to clipboardExpand all lines: src/guide/built-ins/transition-group.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ import ListStagger from './transition-demos/ListStagger.vue'
8
8
9
9
`<TransitionGroup>` is a built-in component designed for animating the insertion, removal, and order change of elements or components that are rendered in a list.
10
10
11
-
## Difference from `<Transition>`
11
+
## Differences from `<Transition>`
12
12
13
13
`<TransitionGroup>` supports the same props, CSS transition classes, and JavaScript hook listeners as `<Transition>`, with the following differences:
14
14
@@ -52,7 +52,7 @@ Here is an example of applying enter / leave transitions to a `v-for` list using
52
52
53
53
## Move Transitions
54
54
55
-
The above demo has some obvious flaws: when an item is inserted or removed, its sorrounding items instantly "jumps" into place instead of moving smoothly. We can fix this by adding a few additional CSS rules:
55
+
The above demo has some obvious flaws: when an item is inserted or removed, its surrounding items instantly "jump" into place instead of moving smoothly. We can fix this by adding a few additional CSS rules:
56
56
57
57
```css{1,13-17}
58
58
.list-move, /* apply transition to moving elements */
@@ -74,7 +74,7 @@ The above demo has some obvious flaws: when an item is inserted or removed, its
74
74
}
75
75
```
76
76
77
-
Now it looks much better - even animates smoothly when the whole list is shuffled:
77
+
Now it looks much better - even animating smoothly when the whole list is shuffled:
Copy file name to clipboardExpand all lines: src/guide/built-ins/transition.md
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Vue offers two built-in components that can help work with transitions and anima
14
14
15
15
-`<Transition>` for applying animations when an element or component is entering and leaving the DOM. This is covered on this page.
16
16
17
-
-`<TransitionGroup>` for applying animations when an element or component is inserted into, removed from, or moved within a `v-for` list. This is covered in the next chapter.
17
+
-`<TransitionGroup>` for applying animations when an element or component is inserted into, removed from, or moved within a `v-for` list. This is covered in [the next chapter](/guide/built-ins/transition-group.html).
18
18
19
19
Aside from these two components, we can also apply animations in Vue using other techniques such as toggling CSS classes or state-driven animations via style bindings. These additional techniques are covered in the [Animation Techniques](/guide/extras/animation.html) chapter.
20
20
@@ -125,7 +125,7 @@ For a named transition, its transition classes will be prefixed with its name in
125
125
126
126
`<Transition>` is most commonly used in combination with [native CSS transitions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions), as seen in the basic example above. The `transition` CSS property is a shorthand that allows us to specify multiple aspects of a transition, including properties that should be animated, duration of the transition, and [easing curves](https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function).
127
127
128
-
Here is a more advanced example transitioning more than one properties, with different duration and easing curves for enter and leave:
128
+
Here is a more advanced example that transitions multiple properties, with different durations and easing curves for enter and leave:
129
129
130
130
```vue-html
131
131
<Transition name="slide-fade">
@@ -319,9 +319,9 @@ You may notice that the animations shown above are mostly using properties like
319
319
320
320
1. They do not affect the document layout during the animation, so they do not trigger expensive CSS layout calculation on every animation frame.
321
321
322
-
2. Most modern browsers can leverage GPU hardware accelaration when animating `transform`.
322
+
2. Most modern browsers can leverage GPU hardware acceleration when animating `transform`.
323
323
324
-
In comparision, properties like `height` or `margin` will trigger CSS layout, so they are much more expensive to animate, and should be used with caution. We can check resources like [CSS-Triggers](https://csstriggers.com/) to see which properties will trigger layout if we animate them.
324
+
In comparison, properties like `height` or `margin` will trigger CSS layout, so they are much more expensive to animate, and should be used with caution. We can check resources like [CSS-Triggers](https://csstriggers.com/) to see which properties will trigger layout if we animate them.
325
325
326
326
## JavaScript Hooks
327
327
@@ -362,7 +362,7 @@ function onAfterEnter(el) {}
362
362
functiononEnterCancelled(el) {}
363
363
364
364
// called before the leave hook.
365
-
// Most of the time, you shoud just use the leave hook
365
+
// Most of the time, you should just use the leave hook
366
366
functiononBeforeLeave(el) {}
367
367
368
368
// called when the leave transition starts.
@@ -463,13 +463,13 @@ Here's a demo using the [GreenSock library](https://greensock.com/) to perform t
463
463
Transitions can be reused through Vue's component system. To create a reusable transition, we can create a component that wraps the `<Transition>` component and passes down the slot content:
464
464
465
465
```vue{5}
466
-
<!-- MyTransitio.vue -->
466
+
<!-- MyTransition.vue -->
467
467
<script>
468
468
// JavaScript hooks logic...
469
469
</script>
470
470
471
471
<template>
472
-
<!-- wrap the builtin Transition component -->
472
+
<!-- wrap the built-in Transition component -->
473
473
<Transition
474
474
name="my-transition"
475
475
@enter="onEnter"
@@ -523,7 +523,7 @@ In addition to toggling an element with `v-if` / `v-show`, we can also transitio
523
523
524
524
## Transition Modes
525
525
526
-
In the previous example, the entering and leaving elements are animated at the same time, and we had to work make them `position: absolute` to avoid the layout issue when both elements are present in the DOM.
526
+
In the previous example, the entering and leaving elements are animated at the same time, and we had to make them `position: absolute` to avoid the layout issue when both elements are present in the DOM.
527
527
528
528
However, in some cases this isn't an option, or simply isn't the desired behavior. We may want the leaving element to be animated out first, and for the entering element to only be inserted **after** the leaving animation has finished. Orchestrating such animations manually would be very complicated - luckily, we can enable this behavior by passing `<Transition>` a `mode` prop:
529
529
@@ -574,7 +574,7 @@ Here's the previous demo with `mode="out-in"`:
574
574
575
575
This can be useful when you've defined CSS transitions / animations using Vue's transition class conventions and want to switch between them.
576
576
577
-
You can also apply different behavior in JavaScript transition hooks based on current state of your component. Finally, the ultimate way of creating dynamic transitions is through [reusable transition components](#reusable-transitions) that accept props to change the nature of the transition(s) to be used. It may sound cheesy, but the only limit really is your imagination.
577
+
You can also apply different behavior in JavaScript transition hooks based on the current state of your component. Finally, the ultimate way of creating dynamic transitions is through [reusable transition components](#reusable-transitions) that accept props to change the nature of the transition(s) to be used. It may sound cheesy, but the only limit really is your imagination.
0 commit comments