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/components/async.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Basic Usage
4
4
5
-
In large applications, we may need to divide the app into smaller chunks and only load a component from the server when it's needed. To make that possible, Vue has a [`defineAsyncComponent`](/api/general.html#defineasynccomponent)method:
5
+
In large applications, we may need to divide the app into smaller chunks and only load a component from the server when it's needed. To make that possible, Vue has a [`defineAsyncComponent`](/api/general.html#defineasynccomponent)function:
As you can see, this method accepts a loader function that returns a Promise. The Promise's `resolve` callback should be called when you have retrieved your component definition from the server. You can also call `reject(reason)` to indicate the load has failed.
19
+
As you can see, `defineAsyncComponent` accepts a loader function that returns a Promise. The Promise's `resolve` callback should be called when you have retrieved your component definition from the server. You can also call `reject(reason)` to indicate the load has failed.
20
20
21
21
[ES module dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports) also returns a Promise, so most of the time we will use it in combination with `defineAsyncComponent`. Bundlers like Vite and webpack also support the syntax, so we can use it to import Vue SFCs:
Copy file name to clipboardExpand all lines: src/guide/components/attrs.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ Then the final rendered DOM would now become:
46
46
47
47
### `v-on` Listener Inheritance
48
48
49
-
Same rule applies to `v-on` event listeners:
49
+
The same rule applies to `v-on` event listeners:
50
50
51
51
```vue-html
52
52
<MyButton @click="onClick" />
@@ -94,15 +94,15 @@ export default {
94
94
95
95
</div>
96
96
97
-
The common scenario for disabling an attribute inheritance is when attributes need to be applied to other elements besides the root node. By setting the `inheritAttrs` option to `false`, you can take full control over where the fallthrough attributes should be applied to.
97
+
The common scenario for disabling attribute inheritance is when attributes need to be applied to other elements besides the root node. By setting the `inheritAttrs` option to `false`, you can take full control over where the fallthrough attributes should be applied.
98
98
99
99
These fallthrough attributes can be accessed directly in template expressions as `$attrs`:
100
100
101
101
```vue-html
102
102
<span>Fallthrough attributes: {{ $attrs }}</span>
103
103
```
104
104
105
-
The `$attrs` object includes all attributes not included to component `props`and`emits`properties (e.g., `class`, `style`, `v-on` listeners, etc.).
105
+
The `$attrs` object includes all attributes that are not declared by the component's`props`or`emits`options (e.g., `class`, `style`, `v-on` listeners, etc.).
106
106
107
107
Using our `<MyButton>` component example from the [previous section](#attribute-inheritance) - sometimes we may need to wrap the actual `<button>` element with an extra `<div>` for styling purposes:
108
108
@@ -120,11 +120,11 @@ We want all fallthrough attributes like `class` and `v-on` listeners to be appli
120
120
</div>
121
121
```
122
122
123
-
Remember that [`v-bind` without argument](/guide/essentials/template-syntax.html#dynamically-binding-multiple-attributes) binds every property of an object as attributes to the target element.
123
+
Remember that [`v-bind` without an argument](/guide/essentials/template-syntax.html#dynamically-binding-multiple-attributes) binds all the properties of an object as attributes of the target element.
124
124
125
125
## Attribute Inheritance on Multiple Root Nodes
126
126
127
-
Unlike single root node components, components with multiple root nodes do not have an automatic attribute fallthrough behavior. If `$attrs` are not bound explicitly, a runtime warning will be issued.
127
+
Unlike components with a single root node, components with multiple root nodes do not have an automatic attribute fallthrough behavior. If `$attrs` are not bound explicitly, a runtime warning will be issued.
Copy file name to clipboardExpand all lines: src/guide/components/events.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ The `.once` modifier is also supported on component event listeners:
29
29
<MyComponent @some-event.once="callback" />
30
30
```
31
31
32
-
Like components and props, event names provide an automatic case transformation. Notice we emitted a camelCase event, but is able to listen to it using a kebab-cased listener in the parent. As with [props casing](/guide/components/props.html#prop-name-casing), we recommend using kebab-cased event listeners in templates.
32
+
Like components and props, event names provide an automatic case transformation. Notice we emitted a camelCase event, but can listen for it using a kebab-cased listener in the parent. As with [props casing](/guide/components/props.html#prop-name-casing), we recommend using kebab-cased event listeners in templates.
33
33
34
34
:::tip
35
35
Unlike native DOM events, component emitted events do **not** bubble. You can only listen to the events emitted by a direct child component.
@@ -45,7 +45,7 @@ It's sometimes useful to emit a specific value with an event. For example, we ma
45
45
</button>
46
46
```
47
47
48
-
Then when we listen to the event in the parent, we can use an inline arrow function as the listener, which allows us to access the event argument:
48
+
Then, when we listen to the event in the parent, we can use an inline arrow function as the listener, which allows us to access the event argument:
49
49
50
50
```vue-html
51
51
<MyButton @increase-by="(n) => count += n" />
@@ -169,12 +169,12 @@ See also: [Typing Component Emits](/guide/typescript/options-api.html#typing-com
169
169
Although optional, it is recommended to define all emitted events in order to better document how a component should work. It also allows Vue to exclude known listeners from [fallthrough attributes](/guide/components/attrs.html#v-on-listener-inheritance).
170
170
171
171
:::tip
172
-
If a native event (e.g., `click`) is defined in the `emits` option, the listener will now only listen to component-emitted `click`event and no longer respond to native `click` events.
172
+
If a native event (e.g., `click`) is defined in the `emits` option, the listener will now only listen to component-emitted `click`events and no longer respond to native `click` events.
173
173
:::
174
174
175
175
## Events Validation
176
176
177
-
Similar to prop type validation, an emitted event can be validated if it is defined with the Object syntax instead of the array syntax.
177
+
Similar to prop type validation, an emitted event can be validated if it is defined with the object syntax instead of the array syntax.
178
178
179
179
To add validation, the event is assigned a function that receives the arguments passed to the `emit` call and returns a boolean to indicate whether the event is valid or not.
180
180
@@ -385,7 +385,7 @@ By default, `v-model` on a component uses `modelValue` as the prop and `update:m
385
385
<MyComponent v-model:title="bookTitle" />
386
386
```
387
387
388
-
In this case, child component should expect a `title` prop and emit `update:title` event to update the parent value:
388
+
In this case, the child component should expect a `title` prop and emit an`update:title` event to update the parent value:
Copy file name to clipboardExpand all lines: src/guide/components/props.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -154,7 +154,7 @@ We use [PascalCase for component tags](/guide/components/registration.html#compo
154
154
155
155
### Static vs. Dynamic Props
156
156
157
-
So far, you've seen props passed as static value, like in:
157
+
So far, you've seen props passed as static values, like in:
158
158
159
159
```vue-html
160
160
<BlogPost title="My journey with Vue" />
@@ -418,7 +418,7 @@ defineProps({
418
418
```
419
419
420
420
:::tip
421
-
Code inside the `defineProps()` argument **cannot access other variables declared in `<script setup>`**, because the entire expression is moved out to an outer function scoped when compiled.
421
+
Code inside the `defineProps()` argument **cannot access other variables declared in `<script setup>`**, because the entire expression is moved to an outer function scope when compiled.
422
422
:::
423
423
424
424
</div>
@@ -483,7 +483,7 @@ If using [Type-based props declarations](/api/sfc-script-setup.html#typescript-o
483
483
<divclass="options-api">
484
484
485
485
::: tip Note
486
-
Note that props are validated **before** a component instance is created, so instance properties (e.g. `data`, `computed`, etc) will not be available inside `default` or `validator` functions.
486
+
Note that props are validated **before** a component instance is created, so instance properties (e.g. `data`, `computed`, etc.) will not be available inside `default` or `validator` functions.
Copy file name to clipboardExpand all lines: src/guide/components/provide-inject.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
## Props Drilling
6
6
7
-
Usually, when we need to pass data from the parent to child component, we use [props](/guide/components/props). However, imagine the case where we have a large component tree, and a deeply nested component needs something from a distant ancestor component. With only props, we would have to pass the same prop across the entire parent chain:
7
+
Usually, when we need to pass data from the parent to a child component, we use [props](/guide/components/props). However, imagine the case where we have a large component tree, and a deeply nested component needs something from a distant ancestor component. With only props, we would have to pass the same prop across the entire parent chain:
The `provide()` function accepts two arguments. The first argument is called the **injection key**, which can be a string or a `Symbol`. The injection key is used by descendent components to lookup the desired value to inject. A single component can call `provide()` multiple times with different injection keys to provide different values.
48
48
49
-
The second argument is the provided value. The value can be of any type. including reactive state such as refs:
49
+
The second argument is the provided value. The value can be of any type, including reactive state such as refs:
50
50
51
51
```js
52
52
import { ref, provide } from'vue'
@@ -193,7 +193,7 @@ Here, the component will locate a property provided with the key `"message"`, an
193
193
194
194
### Injection Default Values
195
195
196
-
By default, `inject` assumes that the injected key is provided somewhere in the parent chian. In the case where the key is not provided, there will be a runtime warning.
196
+
By default, `inject` assumes that the injected key is provided somewhere in the parent chain. In the case where the key is not provided, there will be a runtime warning.
197
197
198
198
If we want to make an injected property work with optional providers, we need to declare a default value, similar to props:
199
199
@@ -221,11 +221,11 @@ export default {
221
221
// when declaring default values for injections
222
222
inject: {
223
223
message: {
224
-
from:'message', // this is optional is using the same key for injection
224
+
from:'message', // this is optional if using the same key for injection
225
225
default:'default value'
226
226
},
227
227
user: {
228
-
// make sure to use factory function for non-primitive values!
228
+
// make sure to use a factory function for non-primitive values!
229
229
default: () => ({ name:'John' })
230
230
}
231
231
}
@@ -240,7 +240,7 @@ export default {
240
240
241
241
When using reactive provide / inject values, **it is recommended to keep any mutations to reactive state inside of the _provider_ whenever possible**. This ensures that the provided state and its possible mutations are co-located in the same component, making it easier to maintain in the future.
242
242
243
-
There may be times where we need to update the data from a injector component. In such cases, we recommend providing a method that is responsible for mutating the state:
243
+
There may be times when we need to update the data from a injector component. In such cases, we recommend providing a function that is responsible for mutating the state:
Copy file name to clipboardExpand all lines: src/guide/components/registration.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ app
40
40
.component('ComponentC', ComponentC)
41
41
```
42
42
43
-
Globally registered components can be used in the template of any component instance within this application:
43
+
Globally registered components can be used in the template of any component within this application:
44
44
45
45
```vue-html
46
46
<!-- this will work in any component inside the app -->
@@ -55,15 +55,15 @@ This even applies to all subcomponents, meaning all three of these components wi
55
55
56
56
While convenient, global registration has a few drawbacks:
57
57
58
-
1. Global registration prevents build systems from removing unused components (a.k.a "tree-shaking"). If you globally register a component but ends up not using it anywhere in your app, it will still be included in the final bundle.
58
+
1. Global registration prevents build systems from removing unused components (a.k.a "tree-shaking"). If you globally register a component but end up not using it anywhere in your app, it will still be included in the final bundle.
59
59
60
-
2. Global registration makes dependency relationships less explicit in large applications. It makes it difficult to locate a child component'simplementationfrom a parent component using it. This can affect longterm maintainability similar to using too many global variables.
60
+
2. Global registration makes dependency relationships less explicit in large applications. It makes it difficult to locate a child component'simplementationfrom a parent component using it. This can affect long-term maintainability similar to using too many global variables.
61
61
62
-
Local registration scopes the availability of the registered components to the current component only. It makes the dependency relationship more explicit, and is more tree-shaking-friendly.
62
+
Local registration scopes the availability of the registered components to the current component only. It makes the dependency relationship more explicit, and is more tree-shakingfriendly.
63
63
64
64
<div class="composition-api">
65
65
66
-
When using SFCwith`<script setup>`, imported components are automatically local-registered:
66
+
When using SFCwith`<script setup>`, imported components are automatically registered locally:
67
67
68
68
```vue
69
69
<script setup>
@@ -93,7 +93,7 @@ export default {
93
93
</div>
94
94
<div class="options-api">
95
95
96
-
Local registration are done using the `components` option:
96
+
Local registration is done using the `components` option:
97
97
98
98
```vue
99
99
<script>
@@ -128,7 +128,7 @@ Note that **locally registered components are _not_ also available in descendent
128
128
129
129
## Component Name Casing
130
130
131
-
Throughout the guide, we are using PascalCase for component registration names. This is because:
131
+
Throughout the guide, we are using PascalCase names when registering components. This is because:
132
132
133
133
1. PascalCase names are valid JavaScript identifiers. This makes it easier to import and register components in JavaScript. It also helps IDEs with auto-completion.
Copy file name to clipboardExpand all lines: src/guide/components/slots.md
+14-15
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ For example, we may have a `<FancyButton>` component that supports usage like th
14
14
</FancyButton>
15
15
```
16
16
17
-
This is how the template of `<FancyButton>` looks like:
17
+
The template of `<FancyButton>` looks like this:
18
18
19
19
```vue-html{2}
20
20
<button class="fancy-btn">
@@ -124,7 +124,7 @@ We might want the text "Submit" to be rendered inside the `<button>` if the pare
124
124
</button>
125
125
```
126
126
127
-
Now when we use `<submit-button>` in a parent component, providing no content for the slot:
127
+
Now when we use `<SubmitButton>` in a parent component, providing no content for the slot:
128
128
129
129
```vue-html
130
130
<SubmitButton />
@@ -195,7 +195,7 @@ For these cases, the `<slot>` element has a special attribute, `name`, which can
195
195
196
196
A `<slot>` outlet without `name` implicitly has the name "default".
197
197
198
-
In a parent component using `<BaseLayout>`, we need a way to pass multiple slot content framgents, each targeting a different slot outlet. This is where **named slots**comes in.
198
+
In a parent component using `<BaseLayout>`, we need a way to pass multiple slot content fragments, each targeting a different slot outlet. This is where **named slots**come in.
199
199
200
200
To pass a named slot, we need to use a `<template>` element with the `v-slot` directive, and then pass the name of the slot as an argument to `v-slot`:
201
201
@@ -213,7 +213,7 @@ To pass a named slot, we need to use a `<template>` element with the `v-slot` di
Here's the code passing content to all three slots to `<BaseLayout>` using the shorthand syntax:
216
+
Here's the code passing content for all three slots to `<BaseLayout>` using the shorthand syntax:
217
217
218
218
```vue-html
219
219
<BaseLayout>
@@ -232,7 +232,7 @@ Here's the code passing content to all three slots to `<BaseLayout>` using the s
232
232
</BaseLayout>
233
233
```
234
234
235
-
When a component accepts both default slot and named slots, all top-level non-`<template>` nodes are implciitly treated as content for default slot. So the above can also be written as:
235
+
When a component accepts both a default slot and named slots, all top-level non-`<template>` nodes are implicitly treated as content for the default slot. So the above can also be written as:
236
236
237
237
```vue-html
238
238
<BaseLayout>
@@ -317,7 +317,7 @@ function BaseLayout(slots) {
317
317
</base-layout>
318
318
```
319
319
320
-
Do note the expression is subject to the same [syntax constraints](/guide/essentials/template-syntax.html#directives) of dynamic directive arguments.
320
+
Do note the expression is subject to the [syntax constraints](/guide/essentials/template-syntax.html#directives) of dynamic directive arguments.
321
321
322
322
## Scoped Slots
323
323
@@ -337,9 +337,9 @@ In fact, we can do exactly that - we can pass attributes to a slot outlet just l
337
337
Receiving the slot props is a bit different when using a single default slot vs. using named slots. We are going to show how to receive props using a single default slot first, by using `v-slot` directly on the child component tag:
338
338
339
339
```vue-html
340
-
<MyComonent v-slot="slotProps">
340
+
<MyComponent v-slot="slotProps">
341
341
{{ slotProps.text }} {{ slotProps.count }}
342
-
<MyComponent>
342
+
</MyComponent>
343
343
```
344
344
345
345
<divclass="composition-api">
@@ -353,7 +353,7 @@ Receiving the slot props is a bit different when using a single default slot vs.
353
353
354
354
</div>
355
355
356
-
The props passed to the slot by the child is available as the value of the corresponding `v-slot` directive, which can be accessed by expressions inside the slot.
356
+
The props passed to the slot by the child are available as the value of the corresponding `v-slot` directive, which can be accessed by expressions inside the slot.
357
357
358
358
You can think of a scoped slot as a function being passed into the child component. The child component then calls it and passing props as arguments:
359
359
@@ -378,13 +378,12 @@ function MyComponent(slots) {
378
378
379
379
In fact, this is very close to how scoped slots are compiled, and how you would use scoped slots in manual [render functions](/guide/extras/render-function.html).
380
380
381
-
Notice how `v-slot="slotProps"` matches the slot function signature - this means similar to function arguments, we can use destructuring in `v-slot`:
382
-
381
+
Notice how `v-slot="slotProps"` matches the slot function signature. Just like with function arguments, we can use destructuring in `v-slot`:
383
382
384
383
```vue-html
385
-
<MyComonent v-slot="{ text, count }">
384
+
<MyComponent v-slot="{ text, count }">
386
385
{{ text }} {{ count }}
387
-
<MyComponent>
386
+
</MyComponent>
388
387
```
389
388
390
389
### Named Scoped Slots
@@ -456,9 +455,9 @@ Inside `<FancyList>`, we can render the same `<slot>` multiple times with differ
456
455
457
456
The `<FancyList>` use case we discussed above encapsulates both reusable logic (data fetching, pagination etc.) and visual output, while delegating part of the visual output to the consumer component via scoped slots.
458
457
459
-
If we push this concept a bit further, we can come up with components that only encapsulate logic and do not render anything by themselves - visual output is fully delegated to the consumer component with scoped slots. We call this type of components **Renderless Components**.
458
+
If we push this concept a bit further, we can come up with components that only encapsulate logic and do not render anything by themselves - visual output is fully delegated to the consumer component with scoped slots. We call this type of component a **Renderless Component**.
460
459
461
-
An exmaple renderless component could be one that encapsulates the logic of tracking the current mouse position:
460
+
An example renderless component could be one that encapsulates the logic of tracking the current mouse position:
0 commit comments