Skip to content

Commit 7399610

Browse files
progressi props
1 parent 9b55653 commit 7399610

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

src/guide/components/async.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { defineAsyncComponent } from 'vue'
1010
const AsyncComp = defineAsyncComponent(() => {
1111
return new Promise((resolve, reject) => {
1212
// ...carica il componente dal server
13-
resolve(/* componente montato */)
13+
resolve(/* componente caricato */)
1414
})
1515
})
1616
// ... utilizzo normale del componente

src/guide/components/props.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -192,47 +192,47 @@ Negli esempi sopra, casualmente abbiamo passato valori di tipo stringa, ma _qua
192192
#### Booleani {#boolean}
193193

194194
```vue-html
195-
<!-- Including the prop with no value will imply `true`. -->
195+
<!-- Includere la prop senza valore implicherà `true`. -->
196196
<BlogPost is-published />
197197
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. -->
200200
<BlogPost :is-published="false" />
201201
202-
<!-- Dynamically assign to the value of a variable. -->
202+
<!-- Assegnare dinamicamente al valore di una variabile. -->
203203
<BlogPost :is-published="post.isPublished" />
204204
```
205205

206206
#### Array {#array}
207207

208208
```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. -->
212211
213-
<!-- Dynamically assign to the value of a variable. -->
212+
<BlogPost :comment-ids="[234, 266, 273]" />
213+
<!-- Assegnare dinamicamente al valore di una variabile. -->
214214
<BlogPost :comment-ids="post.commentIds" />
215215
```
216216

217-
#### Object {#object}
217+
#### Oggetti {#object}
218218

219219
```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. -->
222222
<BlogPost
223-
:author="{
224-
name: 'Veronica',
225-
company: 'Veridian Dynamics'
223+
:author="{
224+
name: 'Veronica',
225+
company: 'Veridian Dynamics'
226226
}"
227-
/>
227+
/>
228228
229-
<!-- Dynamically assign to the value of a variable. -->
229+
<!-- Assegnare dinamicamente al valore di una variabile. -->
230230
<BlogPost :author="post.author" />
231231
```
232232

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}
234234

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`:
236236

237237
<div class="options-api">
238238

@@ -261,30 +261,30 @@ const post = {
261261

262262
</div>
263263

264-
The following template:
264+
Il seguente codice:
265265

266266
```vue-html
267267
<BlogPost v-bind="post" />
268268
```
269269

270-
Will be equivalent to:
270+
Sarà equivalente a:
271271

272272
```vue-html
273273
<BlogPost :id="post.id" :title="post.title" />
274274
```
275275

276-
## One-Way Data Flow {#one-way-data-flow}
276+
## Flusso unidirezionale dei dati {#one-way-data-flow}
277277

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.
279279

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:
281281

282282
<div class="composition-api">
283283

284284
```js
285285
const props = defineProps(['foo'])
286286

287-
//warning, props are readonly!
287+
//Attenzione, le props sono readonly!
288288
props.foo = 'bar'
289289
```
290290

@@ -295,25 +295,25 @@ props.foo = 'bar'
295295
export default {
296296
props: ['foo'],
297297
created() {
298-
//warning, props are readonly!
298+
//Attenzione, le props sono readonly!
299299
this.foo = 'bar'
300300
}
301301
}
302302
```
303303

304304
</div>
305305

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:
307307

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:
309309

310310
<div class="composition-api">
311311

312312
```js
313313
const props = defineProps(['initialCounter'])
314314

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.
317317
const counter = ref(props.initialCounter)
318318
```
319319

@@ -325,8 +325,8 @@ There are usually two cases where it's tempting to mutate a prop:
325325
props: ['initialCounter'],
326326
data() {
327327
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.
330330
counter: this.initialCounter
331331
}
332332
}
@@ -335,14 +335,14 @@ There are usually two cases where it's tempting to mutate a prop:
335335

336336
</div>
337337

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:
339339

340340
<div class="composition-api">
341341

342342
```js
343343
const props = defineProps(['size'])
344344

345-
// computed property that auto-updates when the prop changes
345+
// computed property che fa un auto-update quando la prop cambia
346346
const normalizedSize = computed(() => props.size.trim().toLowerCase())
347347
```
348348

@@ -353,7 +353,7 @@ There are usually two cases where it's tempting to mutate a prop:
353353
export default {
354354
props: ['size'],
355355
computed: {
356-
// computed property that auto-updates when the prop changes
356+
// computed property che fa un auto-update quando la prop cambia
357357
normalizedSize() {
358358
return this.size.trim().toLowerCase()
359359
}
@@ -363,51 +363,51 @@ There are usually two cases where it's tempting to mutate a prop:
363363

364364
</div>
365365

366-
### Mutating Object / Array Props {#mutating-object-array-props}
366+
### Modifica props Oggetto / Array{#mutating-object-array-props}
367367

368-
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.
369369

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.
371371

372-
## Prop Validation {#prop-validation}
372+
## Validazione delle props {#prop-validation}
373373

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.
375375

376-
To specify prop validations, you can provide an object with validation requirements to the <span class="composition-api">`defineProps()` macro</span><span class="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 <span class="composition-api">`defineProps()`</span><span class="options-api">opzione `props`</span>, invece di un array di stringhe. Ad esempio:
377377

378378
<div class="composition-api">
379379

380380
```js
381381
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)
384384
propA: Number,
385-
// Multiple possible types
385+
// Diversi tipi possibili
386386
propB: [String, Number],
387-
// Required string
387+
// Stringa obbligatoria
388388
propC: {
389389
type: String,
390390
required: true
391391
},
392-
// Number with a default value
392+
// Numero con un valore predefinito
393393
propD: {
394394
type: Number,
395395
default: 100
396396
},
397-
// Object with a default value
397+
// Oggetto con un valore predefinito
398398
propE: {
399399
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
408408
propF: {
409409
validator(value) {
410-
// The value must match one of these strings
410+
// Il valore deve corrispondere a una di queste stringhe
411411
return ['success', 'warning', 'danger'].includes(value)
412412
}
413413
},

0 commit comments

Comments
 (0)