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/api/component-instance.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -170,13 +170,13 @@ An object that contains the component's fallthrough attributes.
170
170
171
171
-**Details**
172
172
173
-
[Fallthrough Attributes](/guide/components/attrs.html) are attributes and event handlers passed by the parent component, but not declared as a prop or an emitted event by the child.
173
+
[Attributs implicitement déclarés](/guide/components/attrs.html) are attributes and event handlers passed by the parent component, but not declared as a prop or an emitted event by the child.
174
174
175
175
By default, everything in `$attrs` will be automatically inherited on the component's root element if there is only a single root element. This behavior is disabled if the component has multiple root nodes, and can be explicitly disabled with the [`inheritAttrs`](./options-misc.html#inheritattrs) option.
Copy file name to clipboardExpand all lines: src/api/options-state.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -393,7 +393,7 @@ Declare the custom events emitted by the component.
393
393
394
394
The validation function will receive the additional arguments passed to the component's `$emit` call. For example, if `this.$emit('foo', 1)` is called, the corresponding validator for `foo` will receive the argument `1`. The validator function should return a boolean to indicate whether the event arguments are valid.
395
395
396
-
Note that the `emits` option affects which event listeners are considered component event listeners, rather than native DOM event listeners. The listeners for declared events will be removed from the component's `$attrs` object, so they will not be passed through to the component's root element. See [Fallthrough Attributes](/guide/components/attrs.html) for more details.
396
+
Note that the `emits` option affects which event listeners are considered component event listeners, rather than native DOM event listeners. The listeners for declared events will be removed from the component's `$attrs` object, so they will not be passed through to the component's root element. See [Attributs implicitement déclarés](/guide/components/attrs.html) for more details.
397
397
398
398
- **Example**
399
399
@@ -429,7 +429,7 @@ Declare the custom events emitted by the component.
> This page assumes you've already read the [Components Basics](/guide/essentials/component-basics). Read that first if you are new to components.
7
+
> Cette page suppose que vous avez déjà lu les [bases à propos des composants](/guide/essentials/component-basics). Lisez-les d'abord si vous débutez avec les composants.
8
8
9
-
## Attribute Inheritance
9
+
## Héritage d'attribut {#attribute-inheritance}
10
10
11
-
A "fallthrough attribute" is an attribute or `v-on`event listener that is passed to a component, but is not explicitly declared in the receiving component's [props](./props)or [emits](./events.html#declaring-emitted-events). Common examples of this include `class`, `style`, and`id` attributes.
11
+
Un attribut implicitement déclaré (ou "fallthrough attribute") est un attribut ou un écouteur d'événement `v-on`qui est passé à un composant, mais qui n'est pas explicitement déclaré dans les [props](./props)ou les [émissions](./events.html#declaring-emitted-events) du composant récepteur. Des exemples courants de ceci incluent les attributs `class`, `style` et`id`.
12
12
13
-
When a component renders a single root element, fallthrough attributes will be automatically added to the root element's attributes. For example, given a`<MyButton>`component with the following template:
13
+
Lorsqu'un composant affiche un seul élément racine, les attributs implicitement déclarés sont automatiquement ajoutés aux attributs de l'élément racine. Par exemple, le composant`<MyButton>`avec le template suivant :
14
14
15
15
```vue-html
16
-
<!-- template of <MyButton> -->
16
+
<!-- template de <MyButton> -->
17
17
<button>click me</button>
18
18
```
19
19
20
-
And a parent using this component with:
20
+
Et un parent utilisant ce composant avec :
21
21
22
22
```vue-html
23
23
<MyButton class="large" />
24
24
```
25
25
26
-
The final rendered DOM would be:
26
+
Le DOM rendu final serait :
27
27
28
28
```html
29
29
<buttonclass="large">click me</button>
30
30
```
31
31
32
-
Here, `<MyButton>`did not declare`class`as an accepted prop. Therefore, `class`is treated as a fallthrough attribute and automatically added to `<MyButton>`'s root element.
32
+
Ici, `<MyButton>`n'a pas déclaré`class`comme une prop acceptée. Par conséquent, `class`est traitée comme un attribut implicitement déclaré et automatiquement ajoutée à l'élément racine de `<MyButton>`.
33
33
34
-
### `class` and `style`Merging
34
+
### Fusion de `class` and `style`{#class-and-style-merging}
35
35
36
-
If the child component's root element already has existing `class`or`style`attributes, it will be merged with the`class`and`style`values that are inherited from the parent. Suppose we change the template of`<MyButton>`in the previous example to:
36
+
Si l'élément racine du composant enfant a déjà des attributs `class`ou`style`existants, il sera fusionné avec les valeurs`class`et`style`héritées du parent. Supposons que nous modifions le template de`<MyButton>`dans l'exemple précédent en :
37
37
38
38
```vue-html
39
-
<!-- template of <MyButton> -->
39
+
<!-- template de <MyButton> -->
40
40
<button class="btn">click me</button>
41
41
```
42
42
43
-
Then the final rendered DOM would now become:
43
+
Ainsi, le DOM final rendu deviendrait :
44
44
45
45
```html
46
46
<buttonclass="btn large">click me</button>
47
47
```
48
48
49
-
### `v-on` Listener Inheritance
49
+
### Héritage de l'écouteur "v-on" {#v-on-listener-inheritance}
50
50
51
-
The same rule applies to `v-on`event listeners:
51
+
La même règle s'applique aux écouteurs d'événements `v-on` :
52
52
53
53
```vue-html
54
54
<MyButton @click="onClick" />
55
55
```
56
56
57
-
The `click`listener will be added to the root element of `<MyButton>`, i.e. the native`<button>` element. When the native `<button>`is clicked, it will trigger the`onClick`method of the parent component. If the native `<button>`already has a `click`listener bound with `v-on`, then both listeners will trigger.
57
+
L'écouteur de `click`sera ajouté à l'élément racine de `<MyButton>`, c'est-à-dire l'élément natif`<button>`. Lorsque le `<button>`natif est cliqué, il déclenchera la méthode`onClick`du composant parent. Si le `<button>`natif a déjà un écouteur de `click`lié à `v-on`, alors les deux écouteurs se déclencheront.
58
58
59
-
### Nested Component Inheritance
59
+
### Héritage des composants imbriqués {#nested-component-inheritance}
60
60
61
-
If a component renders another component as its root node, for example, we refactored `<MyButton>`to render a`<BaseButton>`as its root:
61
+
Si un composant rend un autre composant comme son nœud racine, par exemple, nous avons refactorisé `<MyButton>`pour rendre un`<BaseButton>`comme sa racine :
62
62
63
63
```vue-html
64
-
<!-- template of <MyButton/> that simply renders another component -->
64
+
<!-- template de <MyButton/> qui affiche uniquement un autre composant -->
65
65
<BaseButton />
66
66
```
67
67
68
-
Then the fallthrough attributes received by `<MyButton>`will be automatically forwarded to`<BaseButton>`.
68
+
Alors, les attributs implicitement déclarés reçus par `<MyButton>`seront automatiquement transmis à`<BaseButton>`.
69
69
70
-
Note that:
70
+
Notez que :
71
71
72
-
1.Forwarded attributes do not include any attributes that are declared as props, or `v-on`listeners of declared events by `<MyButton>` - in other words, the declared props and listeners have been "consumed" by`<MyButton>`.
72
+
1.Les attributs transférés n'incluent aucun attribut déclaré en tant que props, ou écouteurs `v-on`d'événements déclarés par `<MyButton>` - en d'autres termes, les props et écouteurs déclarés ont été "consommés" par`<MyButton>`.
73
73
74
-
2.Forwarded attributes may be accepted as props by`<BaseButton>`, if declared by it.
74
+
2.Les attributs transférés peuvent être acceptés comme props par`<BaseButton>`, s'ils sont déclarés par celui-ci.
75
75
76
-
## Disabling Attribute Inheritance
76
+
## Désactivation de l'héritage d'attribut {#disabling-attribute-inheritance}
77
77
78
-
If you do **not**want a component to automatically inherit attributes, you can set`inheritAttrs: false`in the component's options.
78
+
Si vous **ne souhaitez pas**qu'un composant hérite automatiquement des attributs, vous pouvez définir`inheritAttrs: false`dans les options du composant.
79
79
80
80
<divclass="composition-api">
81
81
82
-
If using `<script setup>`, you will need to declare this option using a separate, normal`<script>`block:
82
+
Si vous utilisez `<script setup>`, vous devrez déclarer cette option en utilisant un bloc`<script>`normal séparé :
83
83
84
84
```vue
85
85
<script>
86
-
// use normal <script> to declare options
86
+
// utiliser le <script> normal pour déclarer les options
87
87
export default {
88
88
inheritAttrs: false
89
89
}
90
90
</script>
91
91
92
92
<script setup>
93
-
// ...setup logic
93
+
// ...mise en place de la logique
94
94
</script>
95
95
```
96
96
97
97
</div>
98
98
99
-
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.
99
+
Le scénario courant de désactivation de l'héritage d'attribut est lorsque les attributs doivent être appliqués à des éléments autres que le nœud racine. En définissant l'option`inheritAttrs`sur `false`, vous pouvez prendre le contrôle total sur l'endroit où les attributs fallthrough doivent être appliqués.
100
100
101
-
These fallthrough attributes can be accessed directly in template expressions as `$attrs`:
101
+
Ces attributs sont accessibles directement dans les expressions de template en tant que `$attrs`:
102
102
103
103
```vue-html
104
104
<span>Fallthrough attributes: {{ $attrs }}</span>
105
105
```
106
106
107
-
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.).
107
+
L'objet`$attrs`inclut tous les attributs qui ne sont pas déclarés par les`props`du composant ou options `emits`(par exemple, `class`, `style`, les écouteurs `v-on`, etc.).
108
108
109
-
Some notes:
109
+
Quelques notes:
110
110
111
-
-Unlike props, fallthrough attributes preserve their original casing in JavaScript, so an attribute like`foo-bar`needs to be accessed as`$attrs['foo-bar']`.
111
+
-Contrairement aux props, les attributs implicitement déclarés conservent leur casse d'origine en JavaScript, donc un attribut comme`foo-bar`doit être accédé en tant que`$attrs['foo-bar']`.
112
112
113
-
-A `v-on`event listener like `@click`will be exposed on the object as a function under`$attrs.onClick`.
113
+
-Un écouteur d'événement `v-on`comme `@click`sera exposé sur l'objet en tant que fonction sous`$attrs.onClick`.
114
114
115
-
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:
115
+
En utilisant notre composant exemple `<MyButton>`de la [section précédente](#attribute-inheritance) - nous pouvons parfois avoir besoin d'envelopper l'élément `<button>`réel avec un `<div>`supplémentaire à des fins de style :
116
116
117
117
```vue-html
118
118
<div class="btn-wrapper">
119
119
<button class="btn">click me</button>
120
120
</div>
121
121
```
122
122
123
-
We want all fallthrough attributes like `class`and `v-on`listeners to be applied to the inner `<button>`, not the outer`<div>`. We can achieve this with`inheritAttrs: false`and`v-bind="$attrs"`:
123
+
Nous voulons que tous les attributs implicitement déclarés tels que `class`et les écouteurs `v-on`soient appliqués au `<button>` sous-jacent, et non au`<div>`. Nous pouvons y parvenir avec`inheritAttrs: false`et`v-bind="$attrs"`:
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.
131
+
Rappelez-vous que[`v-bind`sans argument](/guide/essentials/template-syntax.html#dynamically-binding-multiple-attributes)lie toutes les propriétés d'un objet en tant qu'attributs de l'élément cible.
132
132
133
-
## Attribute Inheritance on Multiple Root Nodes
133
+
## Héritage d'attributs sur plusieurs nœuds racine {#attribute-inheritance-on-multiple-root-nodes}
134
134
135
-
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.
135
+
Contrairement aux composants avec un seul nœud racine, les composants avec plusieurs nœuds racine n'ont pas de comportement automatique concenant les attributs impliciitement déclarés. Si`$attrs`n'est pas lié explicitement, un avertissement lors de l'exécution sera émis.
If`<CustomLayout>`has the following multi-root template, there will be a warning because Vue cannot be sure where to apply the fallthrough attributes:
141
+
Si`<CustomLayout>`a le template multi-racine suivant, il y aura un avertissement car Vue ne sait pas où appliquer les attributs implicitement déclarés :
142
142
143
143
```vue-html
144
144
<header>...</header>
145
145
<main>...</main>
146
146
<footer>...</footer>
147
147
```
148
148
149
-
The warning will be suppressed if `$attrs`is explicitly bound:
149
+
L'avertissement sera supprimé si `$attrs`est explicitement lié :
150
150
151
151
```vue-html{2}
152
152
<header>...</header>
153
153
<main v-bind="$attrs">...</main>
154
154
<footer>...</footer>
155
155
```
156
156
157
-
## Accessing Fallthrough Attributes in JavaScript
157
+
## Accéder aux attributs implicitement déclarés en JavaScript {#accessing-fallthrough-attributes-in-javascript}
158
158
159
159
<divclass="composition-api">
160
160
161
-
If needed, you can access a component's fallthrough attributes in `<script setup>`using the `useAttrs()`API:
161
+
Si nécessaire, vous pouvez accéder aux attributs implicitement déclarés d'un composant dans `<script setup>`à l'aide de l'API `useAttrs()` :
162
162
163
163
```vue
164
164
<script setup>
@@ -168,24 +168,24 @@ const attrs = useAttrs()
168
168
</script>
169
169
```
170
170
171
-
If not using `<script setup>`, `attrs`will be exposed as a property of the `setup()`context:
171
+
Si vous n'utilisez pas `<script setup>`, `attrs`sera exposé en tant que propriété du contexte de `setup()` :
172
172
173
173
```js
174
174
exportdefault {
175
175
setup(props, ctx) {
176
-
//fallthrough attributes are exposed as ctx.attrs
176
+
//les attributs implicitement déclarés sont exposés en tant que ctx.attrs
177
177
console.log(ctx.attrs)
178
178
}
179
179
}
180
180
```
181
181
182
-
Note that although the `attrs`object here always reflects the latest fallthrough attributes, it isn't reactive (for performance reasons). You cannot use watchers to observe its changes. If you need reactivity, use a prop. Alternatively, you can use`onUpdated()`to perform side effects with the latest`attrs`on each update.
182
+
Notez que bien que l'objet `attrs`reflète toujours les derniers attributs implicitement déclarés, il n'est pas réactif (pour des raisons de performances). Vous ne pouvez pas utiliser d'observateurs pour observer ses changements. Si vous avez besoin de réactivité, utilisez une prop. De manière alternative, vous pouvez utiliser`onUpdated()`pour effectuer des tâches avec les derniers`attrs`à chaque mise à jour.
183
183
184
184
</div>
185
185
186
186
<divclass="options-api">
187
187
188
-
If needed, you can access a component's fallthrough attributes via the `$attrs`instance property:
188
+
Si nécessaire, vous pouvez accéder aux attributs implicitement déclarés d'un composant via la propriété d'instance `$attrs` :
When used on components, custom directives will always apply to a component's root node, similar to [Fallthrough Attributes](/guide/components/attrs.html).
213
+
When used on components, custom directives will always apply to a component's root node, similar to [Attributs implicitement déclarés](/guide/components/attrs.html).
0 commit comments