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/props.md
+33-33Lines changed: 33 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
1
# Props {#props}
2
2
3
-
> This page assumes you've already read the [Components Basics](/guide/essentials/component-basics). Read that first if you are new to components.
3
+
> Si assume che tu abbia già letto le [Basi dei componenti](/guide/essentials/component-basics). Leggi prima quello se sei nuovo al concetto di componente.
Vue components require explicit props declaration so that Vue knows what external props passed to the component should be treated as fallthrough attributes (which will be discussed in [its dedicated section](/guide/components/attrs)).
11
+
I componenti di Vue richiedono una dichiarazione esplicita delle props affinché Vue sappia come trattare le props esterne passate al componente come attributi passanti (che verranno discusse nella [sezione dedicata](/guide/components/attrs)).
12
12
13
13
<divclass="composition-api">
14
14
15
-
In SFCs using`<script setup>`, props can be declared using the `defineProps()` macro:
15
+
Nei SFC utilizzando`<script setup>`, le props possono essere dichiarate utilizzando la macro `defineProps()`:
16
16
17
17
```vue
18
18
<script setup>
@@ -22,39 +22,39 @@ console.log(props.foo)
22
22
</script>
23
23
```
24
24
25
-
In non-`<script setup>` components, props are declared using the [`props`](/api/options-state#props) option:
25
+
Nei componenti non-`<script setup>`, le props vengono dichiarate utilizzando la sezione [`props`](/api/options-state#props):
26
26
27
27
```js
28
28
exportdefault {
29
29
props: ['foo'],
30
30
setup(props) {
31
-
// setup() receives props as the first argument.
31
+
// setup() prende props come primo parametro
32
32
console.log(props.foo)
33
33
}
34
34
}
35
35
```
36
36
37
-
Notice the argument passed to `defineProps()` is the same as the value provided to the `props` options: the same props options API is shared between the two declaration styles.
37
+
Nota che l'argomento passato a defineProps() è lo stesso valore fornito all'opzione props: la stessa API di opzioni per le props è condivisa tra i due stili di dichiarazione..
38
38
39
39
</div>
40
40
41
41
<divclass="options-api">
42
42
43
-
Props are declared using the [`props`](/api/options-state#props) option:
43
+
Le props vengono dichiarate nella sezione [`props`](/api/options-state#props):
44
44
45
45
```js
46
46
exportdefault {
47
47
props: ['foo'],
48
48
created() {
49
-
//props are exposed on `this`
49
+
//puoi riferirti alle props con `this`
50
50
console.log(this.foo)
51
51
}
52
52
}
53
53
```
54
54
55
55
</div>
56
56
57
-
In addition to declaring props using an array of strings, we can also use the object syntax:
57
+
Oltre a dichiarare le props utilizzando un array di stringhe, possiamo anche utilizzare la sintassi dell'oggetto:
58
58
59
59
<divclass="options-api">
60
60
@@ -79,7 +79,7 @@ defineProps({
79
79
```
80
80
81
81
```js
82
-
//in non-<script setup>
82
+
// non-<script setup>
83
83
exportdefault {
84
84
props: {
85
85
title:String,
@@ -90,19 +90,19 @@ export default {
90
90
91
91
</div>
92
92
93
-
For each property in the object declaration syntax, the key is the name of the prop, while the value should be the constructor function of the expected type.
93
+
Per ogni proprietà nella sintassi di dichiarazione dell'oggetto, la chiave rappresenta il nome della prop, mentre il valore dovrebbe essere la funzione costruttrice del tipo previsto.
94
94
95
-
This not only documents your component, but will also warn other developers using your component in the browser console if they pass the wrong type. We will discuss more details about [prop validation](#prop-validation)further down this page.
95
+
Questo non solo documenta il componente, ma avvertirà anche gli altri sviluppatori che utilizzano il componente nella console del browser se passano un tipo errato. Discuteremo ulteriori dettagli sulla [validazione delle props](#prop-validation)più avanti in questa pagina.
96
96
97
97
<divclass="options-api">
98
98
99
-
See also: [Typing Component Props](/guide/typescript/options-api#typing-component-props) <supclass="vt-badge ts" />
If you are using TypeScript with`<script setup>`, it's also possible to declare props using pure type annotations:
105
+
Se stai usando TypeScript con`<script setup>`, è anche possibile dichiarare le props utilizzando solo annotazioni di tipo:
106
106
107
107
```vue
108
108
<script setup lang="ts">
@@ -113,15 +113,15 @@ defineProps<{
113
113
</script>
114
114
```
115
115
116
-
More details: [Typing Component Props](/guide/typescript/composition-api#typing-component-props) <supclass="vt-badge ts" />
116
+
Più dettagli: [Typing Component Props](/guide/typescript/composition-api#typing-component-props) <supclass="vt-badge ts" />
117
117
118
118
</div>
119
119
120
-
## Prop Passing Details {#prop-passing-details}
120
+
## Dettagli sul passaggio delle Props {#prop-passing-details}
121
121
122
-
### Prop Name Casing {#prop-name-casing}
122
+
### Casing dei nomi delle Props {#prop-name-casing}
123
123
124
-
We declare long prop names using camelCase because this avoids having to use quotes when using them as property keys, and allows us to reference them directly in template expressions because they are valid JavaScript identifiers:
124
+
Dichiarare i nomi delle props lunghi utilizzando camelCase ci permette di evitare l'uso di virgolette quando li utilizziamo come chiavi di proprietà e ci consente di farvi riferimento direttamente nelle espressioni del template, poiché sono identificatori JavaScript validi:
125
125
126
126
<divclass="composition-api">
127
127
@@ -148,48 +148,48 @@ export default {
148
148
<span>{{ greetingMessage }}</span>
149
149
```
150
150
151
-
Technically, you can also use camelCase when passing props to a child component (except in [DOM templates](/guide/essentials/component-basics#dom-template-parsing-caveats)). However, the convention is using kebab-case in all cases to align with HTML attributes:
151
+
Tecnicamente, puoi anche utilizzare camelCase quando passi props a un componente figlio (ad eccezione dei [template DOM](/guide/essentials/component-basics#dom-template-parsing-caveats)). Tuttavia, la convenzione è utilizzare kebab-case in tutti i casi per allinearsi agli attributi HTML:
152
152
153
153
```vue-html
154
154
<MyComponent greeting-message="hello" />
155
155
```
156
156
157
-
We use [PascalCase for component tags](/guide/components/registration#component-name-casing)when possible because it improves template readability by differentiating Vue components from native elements. However, there isn't as much practical benefit in using camelCase when passing props, so we choose to follow each language's conventions.
157
+
Utilizziamo [PascalCase per i tag dei componenti](/guide/components/registration#component-name-casing) quando possibile poiché migliora la leggibilità del template differenziando i componenti Vue dagli elementi nativi. Tuttavia, non ci sono molti vantaggi pratici nell'utilizzare camelCase quando si passano props, quindi scegliamo di seguire le convenzioni di ciascun linguaggio.
158
158
159
-
### Static vs. Dynamic Props {#static-vs-dynamic-props}
159
+
### Props Statiche vs. Dinamiche {#static-vs-dynamic-props}
160
160
161
-
So far, you've seen props passed as static values, like in:
161
+
Finora, hai visto le props passate come valori statici, come in:
162
162
163
163
```vue-html
164
164
<BlogPost title="My journey with Vue" />
165
165
```
166
166
167
-
You've also seen props assigned dynamically with `v-bind` or its `:` shortcut, such as in:
167
+
Hai anche visto le props assegnate dinamicamente con v-bind o il suo abbreviato :, come ad esempio in:
168
168
169
169
```vue-html
170
-
<!-- Dynamically assign the value of a variable -->
170
+
<!-- Assegna dinamicamente il valore di una variabile -->
171
171
<BlogPost :title="post.title" />
172
172
173
-
<!-- Dynamically assign the value of a complex expression -->
173
+
<!-- Assegna dinamicamente il valore di una espressione complessa -->
174
174
<BlogPost :title="post.title + ' by ' + post.author.name" />
175
175
```
176
176
177
-
### Passing Different Value Types {#passing-different-value-types}
177
+
### Passaggio di diversi tipi di valori {#passing-different-value-types}
178
178
179
-
In the two examples above, we happen to pass string values, but _any_ type of value can be passed to a prop.
179
+
Negli esempi sopra, casualmente abbiamo passato valori di tipo stringa, ma _qualsiasi_ tipo di valore può essere passato a una prop.
180
180
181
-
#### Number {#number}
181
+
#### Numero {#number}
182
182
183
183
```vue-html
184
-
<!-- Even though `42` is static, we need v-bind to tell Vue that -->
185
-
<!-- this is a JavaScript expression rather than a string. -->
184
+
<!-- Anche se `42` è statico, abbiamo bisogno di v-bind per indicare a Vue che -->
185
+
<!-- questa è un'espressione JavaScript piuttosto che una stringa. -->
186
186
<BlogPost :likes="42" />
187
187
188
-
<!-- Dynamically assign to the value of a variable. -->
188
+
<!-- Assegna dinamicamente il valore di una variabile -->
189
189
<BlogPost :likes="post.likes" />
190
190
```
191
191
192
-
#### Boolean {#boolean}
192
+
#### Booleani {#boolean}
193
193
194
194
```vue-html
195
195
<!-- Including the prop with no value will imply `true`. -->
0 commit comments