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
+55-55Lines changed: 55 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -192,47 +192,47 @@ Negli esempi sopra, casualmente abbiamo passato valori di tipo stringa, ma _qua
192
192
#### Booleani {#boolean}
193
193
194
194
```vue-html
195
-
<!-- Including the prop with no value will imply `true`. -->
195
+
<!-- Includere la prop senza valore implicherà `true`. -->
196
196
<BlogPost is-published />
197
197
198
-
<!-- Even though `false` is static, we need v-bind to tell Vue that -->
199
-
<!-- this is a JavaScript expression rather than a string. -->
198
+
<!-- Anche se `false` è statico, abbiamo bisogno di v-bind per dire a Vue che -->
199
+
<!-- questa è un'espressione JavaScript piuttosto che una stringa. -->
200
200
<BlogPost :is-published="false" />
201
201
202
-
<!-- Dynamically assign to the value of a variable. -->
202
+
<!-- Assegnare dinamicamente al valore di una variabile. -->
203
203
<BlogPost :is-published="post.isPublished" />
204
204
```
205
205
206
206
#### Array {#array}
207
207
208
208
```vue-html
209
-
<!-- Even though the array is static, we need v-bind to tell Vue that -->
210
-
<!-- this is a JavaScript expression rather than a string. -->
211
-
<BlogPost :comment-ids="[234, 266, 273]" />
209
+
<!-- Anche se l'array è statico, abbiamo bisogno di v-bind per dire a Vue che -->
210
+
<!-- questa è un'espressione JavaScript piuttosto che una stringa. -->
212
211
213
-
<!-- Dynamically assign to the value of a variable. -->
212
+
<BlogPost :comment-ids="[234, 266, 273]" />
213
+
<!-- Assegnare dinamicamente al valore di una variabile. -->
214
214
<BlogPost :comment-ids="post.commentIds" />
215
215
```
216
216
217
-
#### Object {#object}
217
+
#### Oggetti {#object}
218
218
219
219
```vue-html
220
-
<!-- Even though the object is static, we need v-bind to tell Vue that -->
221
-
<!-- this is a JavaScript expression rather than a string. -->
220
+
<!-- Anche se l'oggetto è statico, abbiamo bisogno di v-bind per dire a Vue che -->
221
+
<!-- questa è un'espressione JavaScript piuttosto che una stringa. -->
222
222
<BlogPost
223
-
:author="{
224
-
name: 'Veronica',
225
-
company: 'Veridian Dynamics'
223
+
:author="{
224
+
name: 'Veronica',
225
+
company: 'Veridian Dynamics'
226
226
}"
227
-
/>
227
+
/>
228
228
229
-
<!-- Dynamically assign to the value of a variable. -->
229
+
<!-- Assegnare dinamicamente al valore di una variabile. -->
230
230
<BlogPost :author="post.author" />
231
231
```
232
232
233
-
### Binding Multiple Properties Using an Object {#binding-multiple-properties-using-an-object}
233
+
### Associazione di più proprietà utilizzando un oggetto {#binding-multiple-properties-using-an-object}
234
234
235
-
If you want to pass all the properties of an object as props, you can use [`v-bind`without an argument](/guide/essentials/template-syntax#dynamically-binding-multiple-attributes) (`v-bind`instead of`:prop-name`). For example, given a `post` object:
235
+
Se desideri passare tutte le proprietà di un oggetto come props, puoi utilizzare [`v-bind`senza un argomento](/guide/essentials/template-syntax#dynamically-binding-multiple-attributes) (`v-bind`invece di`:prop-name`). Ad esempio, dato un oggetto `post`:
236
236
237
237
<divclass="options-api">
238
238
@@ -261,30 +261,30 @@ const post = {
261
261
262
262
</div>
263
263
264
-
The following template:
264
+
Il seguente codice:
265
265
266
266
```vue-html
267
267
<BlogPost v-bind="post" />
268
268
```
269
269
270
-
Will be equivalent to:
270
+
Sarà equivalente a:
271
271
272
272
```vue-html
273
273
<BlogPost :id="post.id" :title="post.title" />
274
274
```
275
275
276
-
## One-Way Data Flow {#one-way-data-flow}
276
+
## Flusso unidirezionale dei dati {#one-way-data-flow}
277
277
278
-
All props form a **one-way-down binding**between the child property and the parent one: when the parent property updates, it will flow down to the child, but not the other way around. This prevents child components from accidentally mutating the parent's state, which can make your app's data flow harder to understand.
278
+
Tutte le props formano un legame **unidirezionale verso il basso**tra la proprietà figlio e quella genitore: quando la proprietà genitore viene aggiornata, essa fluirà verso il basso fino al figlio, ma non viceversa. Questo impedisce ai componenti figlio di mutare accidentalmente lo stato del genitore, il che può rendere più difficile comprendere il flusso dei dati dell'app.
279
279
280
-
In addition, every time the parent component is updated, all props in the child component will be refreshed with the latest value. This means you should **not**attempt to mutate a prop inside a child component. If you do, Vue will warn you in the console:
280
+
Inoltre, ogni volta che il componente genitore viene aggiornato, tutte le props nel componente figlio verranno aggiornate con il valore più recente. Ciò significa che **non**dovresti tentare di mutare una prop all'interno di un componente figlio. Se lo fai, Vue ti avviserà nella console:
281
281
282
282
<divclass="composition-api">
283
283
284
284
```js
285
285
constprops=defineProps(['foo'])
286
286
287
-
// ❌ warning, props are readonly!
287
+
// ❌ Attenzione, le props sono readonly!
288
288
props.foo='bar'
289
289
```
290
290
@@ -295,25 +295,25 @@ props.foo = 'bar'
295
295
exportdefault {
296
296
props: ['foo'],
297
297
created() {
298
-
// ❌ warning, props are readonly!
298
+
// ❌ Attenzione, le props sono readonly!
299
299
this.foo='bar'
300
300
}
301
301
}
302
302
```
303
303
304
304
</div>
305
305
306
-
There are usually two cases where it's tempting to mutate a prop:
306
+
Di solito ci sono due casi in cui è tentativo mutare una prop:
307
307
308
-
1.**The prop is used to pass in an initial value; the child component wants to use it as a local data property afterwards.** In this case, it's best to define a local data property that uses the prop as its initial value:
308
+
1.**La prop viene utilizzata per passare un valore iniziale; il componente figlio vuole usarla successivamente come proprietà dati locale.** In questo caso, è meglio definire una proprietà dati locale che utilizzi la prop come suo valore iniziale:
309
309
310
310
<divclass="composition-api">
311
311
312
312
```js
313
313
constprops=defineProps(['initialCounter'])
314
314
315
-
// counter only uses props.initialCounter as the initial value;
316
-
//it is disconnected from future prop updates.
315
+
// counter utilizza solo props.initialCounter come valore iniziale;
316
+
//è scollegato dagli aggiornamenti futuri della prop.
317
317
constcounter=ref(props.initialCounter)
318
318
```
319
319
@@ -325,8 +325,8 @@ There are usually two cases where it's tempting to mutate a prop:
325
325
props: ['initialCounter'],
326
326
data() {
327
327
return {
328
-
// counter only uses this.initialCounter as the initial value;
329
-
//it is disconnected from future prop updates.
328
+
// counter utilizza solo this.initialCounter come valore iniziale;
329
+
//è scollegato dagli aggiornamenti futuri della prop.
330
330
counter:this.initialCounter
331
331
}
332
332
}
@@ -335,14 +335,14 @@ There are usually two cases where it's tempting to mutate a prop:
335
335
336
336
</div>
337
337
338
-
2.**The prop is passed in as a raw value that needs to be transformed.** In this case, it's best to define a computed property using the prop's value:
338
+
2.**La prop viene passata come un valore grezzo che deve essere trasformato.** In questo caso, è meglio definire una proprietà calcolata che utilizzi il valore della prop:
339
339
340
340
<divclass="composition-api">
341
341
342
342
```js
343
343
constprops=defineProps(['size'])
344
344
345
-
// computed property that auto-updates when the prop changes
345
+
// computed property che fa un auto-update quando la prop cambia
When objects and arrays are passed as props, while the child component cannot mutate the prop binding, it **will**be able to mutate the object or array's nested properties. This is because in JavaScript objects and arrays are passed by reference, and it is unreasonably expensive for Vue to prevent such mutations.
368
+
Quando oggetti e array vengono passati come props, sebbene il componente figlio non possa mutare il legame con la prop, **potrà**mutare le proprietà annidate dell'oggetto o dell'array. Questo perché in JavaScript gli oggetti e gli array vengono passati per riferimento, ed è irragionevolmente costoso per Vue prevenire tali mutazioni.
369
369
370
-
The main drawback of such mutations is that it allows the child component to affect parent state in a way that isn't obvious to the parent component, potentially making it more difficult to reason about the data flow in the future. As a best practice, you should avoid such mutations unless the parent and child are tightly coupled by design. In most cases, the child should [emit an event](/guide/components/events)to let the parent perform the mutation.
370
+
Il principale svantaggio di tali mutazioni è che consentono al componente figlio di influenzare lo stato del genitore in un modo che non è ovvio per il componente genitore, rendendo potenzialmente più difficile ragionare sul flusso dei dati in futuro. Come buona pratica, dovresti evitare tali mutazioni a meno che il genitore e il figlio siano strettamente accoppiati dal design. Nella maggior parte dei casi, il figlio dovrebbe [emettere un evento](/guide/components/events)per permettere al genitore di effettuare il cambiamento.
371
371
372
-
## Prop Validation {#prop-validation}
372
+
## Validazione delle props {#prop-validation}
373
373
374
-
Components can specify requirements for their props, such as the types you've already seen. If a requirement is not met, Vue will warn you in the browser's JavaScript console. This is especially useful when developing a component that is intended to be used by others.
374
+
I componenti possono specificare requisiti per le loro props, come i tipi che hai già visto. Se un requisito non viene soddisfatto, Vue ti avviserà nella console JavaScript del browser. Questo è particolarmente utile quando sviluppi un componente destinato ad essere utilizzato da altri.
375
375
376
-
To specify prop validations, you can provide an object with validation requirements to the <spanclass="composition-api">`defineProps()` macro</span><spanclass="options-api">`props` option</span>, instead of an array of strings. For example:
376
+
Per specificare la validazione delle props, puoi fornire un oggetto con requisiti di validazione alla macro <spanclass="composition-api">`defineProps()`</span><spanclass="options-api">opzione `props`</span>, invece di un array di stringhe. Ad esempio:
377
377
378
378
<divclass="composition-api">
379
379
380
380
```js
381
381
defineProps({
382
-
//Basic type check
383
-
// (`null` and `undefined` values will allow any type)
382
+
//Controllo di base dei tipi
383
+
//(null e undefined consentiranno qualsiasi tipo)
384
384
propA:Number,
385
-
//Multiple possible types
385
+
//Diversi tipi possibili
386
386
propB: [String, Number],
387
-
//Required string
387
+
//Stringa obbligatoria
388
388
propC: {
389
389
type:String,
390
390
required:true
391
391
},
392
-
//Number with a default value
392
+
//Numero con un valore predefinito
393
393
propD: {
394
394
type:Number,
395
395
default:100
396
396
},
397
-
//Object with a default value
397
+
//Oggetto con un valore predefinito
398
398
propE: {
399
399
type:Object,
400
-
//Object or array defaults must be returned from
401
-
//a factory function. The function receives the raw
402
-
//props received by the component as the argument.
403
-
default(rawProps) {
404
-
return { message:'hello' }
405
-
}
406
-
},
407
-
//Custom validator function
400
+
//I valori predefiniti degli oggetti o degli array devono essere restituiti da
401
+
//una funzione di fabbrica. La funzione riceve come argomento le props grezze
402
+
//ricevute dal componente.
403
+
default(rawProps) {
404
+
return { message:'hello' }
405
+
}
406
+
},
407
+
//Funzione di validazione personalizzata
408
408
propF: {
409
409
validator(value) {
410
-
//The value must match one of these strings
410
+
//Il valore deve corrispondere a una di queste stringhe
0 commit comments