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
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
-
# Async Components {#async-components}
1
+
# Componenti asincroni {#async-components}
2
2
3
-
## Basic Usage {#basic-usage}
3
+
## Utilizzo base {#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#defineasynccomponent) function:
5
+
Nelle grandi applicazioni, potrebbe essere necessario dividere l'applicazione in chunk più piccoli e caricare un componente dal server solo quando è necessario. Per rendere ciò possibile, Vue ha una funzione [`defineAsyncComponent`](/api/general#defineasynccomponent):
6
6
7
7
```js
8
8
import { defineAsyncComponent } from'vue'
9
9
10
10
constAsyncComp=defineAsyncComponent(() => {
11
11
returnnewPromise((resolve, reject) => {
12
-
// ...load component from server
13
-
resolve(/*loaded component*/)
12
+
// ...carica il componente dal server
13
+
resolve(/*componente montato*/)
14
14
})
15
15
})
16
-
// ... use `AsyncComp` like a normal component
16
+
// ... utilizzo normale del componente
17
17
```
18
18
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.
19
+
Come si può notare, `defineAsyncComponent`accetta una funzione loader che restituisce una Promise. La funzione`resolve`della Promise dovrebbe essere chiamata quando hai recuperato la definizione del componente dal server. Puoi anche chiamare `reject(reason)`per indicare che il caricamento è fallito.
20
20
21
-
[ES module dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import)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 (and will use it as bundle split points), so we can use it to import Vue SFCs:
21
+
[ES module dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import)restituisce anche una Promise, quindi nella maggior parte dei casi lo useremo in combinazione con`defineAsyncComponent`. I bundler come Vite e webpack supportano anche questa sintassi (e la utilizzeranno per dividere i bundle), quindi possiamo usarla per importare i file SFC di Vue.
The resulting `AsyncComp`is a wrapper component that only calls the loader function when it is actually rendered on the page. In addition, it will pass along any props and slots to the inner component, so you can use the async wrapper to seamlessly replace the original component while achieving lazy loading.
31
+
Il componente risultante `AsyncComp`è un componente wrapper che chiama la funzione di caricamento solo quando viene effettivamente reso nella pagina. Inoltre, passerà tutte le props e gli slot al componente interno, consentendoti di utilizzare il wrapper asincrono per sostituire senza problemi il componente originale ottenendo il lazy loading.
32
32
33
-
As with normal components, async components can be [registered globally](/guide/components/registration#global-registration)using`app.component()`:
33
+
Come con i componenti normali, i componenti asincroni possono essere [registrati globalmente](/guide/components/registration#global-registration)utilizzando`app.component()`:
## Loading and Error States {#loading-and-error-states}
85
+
## Stati di caricamento e di errore {#stati-di-caricamento-e-di-errore}
86
86
87
-
Asynchronous operations inevitably involve loading and error states - `defineAsyncComponent()`supports handling these states via advanced options:
87
+
Le operazioni asincrone implicano inevitabilmente stati di caricamento e di errore. `defineAsyncComponent()`supporta la gestione di questi stati tramite opzioni avanzate:
88
88
89
89
```js
90
90
constAsyncComp=defineAsyncComponent({
91
-
//the loader function
91
+
//la funzione loader
92
92
loader: () =>import('./Foo.vue'),
93
93
94
-
//A component to use while the async component is loading
94
+
//Componente utilizzato durante il caricamento dell'async component
95
95
loadingComponent: LoadingComponent,
96
-
//Delay before showing the loading component. Default: 200ms.
96
+
//Ritardo prima di mostrare il componente di caricamento. Predefinito: 200ms.
97
97
delay:200,
98
98
99
-
//A component to use if the load fails
99
+
//Componente utilizzato se il caricamento fallisce
100
100
errorComponent: ErrorComponent,
101
-
// The error component will be displayed if a timeout is
102
-
// provided and exceeded. Default: Infinity.
101
+
// Il componente di errore verrà mostrato se viene fornito un timeout ed è superato. Predefinito: Infinity.
103
102
timeout:3000
104
103
})
105
104
```
106
105
107
-
If a loading component is provided, it will be displayed first while the inner component is being loaded. There is a default 200ms delay before the loading component is shown - this is because on fast networks, an instant loading state may get replaced too fast and end up looking like a flicker.
106
+
Se viene fornito un componente di caricamento, verrà mostrato prima mentre l'inner component viene caricato. C'è un ritardo predefinito di 200 ms prima che il componente di caricamento venga mostrato - questo perché su reti veloci, uno stato di caricamento istantaneo potrebbe essere sostituito troppo velocemente e sembrare un lampeggio.
108
107
109
-
If an error component is provided, it will be displayed when the Promise returned by the loader function is rejected. You can also specify a timeout to show the error component when the request is taking too long.
108
+
Se viene fornito un componente di errore, verrà mostrato quando la Promise restituita dalla funzione di caricamento viene rifiutata. È anche possibile specificare un timeout per mostrare il componente di errore quando la richiesta sta richiedendo troppo tempo.
110
109
111
110
## Using with Suspense {#using-with-suspense}
112
111
113
-
Async components can be used with the `<Suspense>` built-in component. The interaction between`<Suspense>`and async components is documented in the [dedicated chapter for`<Suspense>`](/guide/built-ins/suspense).
112
+
I componenti asincroni possono essere utilizzati con il componente integrato `<Suspense>`. L'interazione tra`<Suspense>`e i componenti asincroni è documentata nel [capitolo dedicato a`<Suspense>`](/guide/built-ins/suspense).
Copy file name to clipboardExpand all lines: src/guide/typescript/overview.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Vue stesso è scritto in TypeScript e offre un supporto TypeScript di prima clas
10
10
11
11
## Creare un applicazione {#project-setup}
12
12
13
-
[`create-vue`](https://github.com/vuejs/create-vue), il tool ufficiale, offre la possibilità di creare un progetto [Vite](https://vitejs.dev/) TypeScript-ready.
13
+
[`create-vue`](https://github.com/vuejs/create-vue), il tool ufficiale, offre la possibilità di creare un progetto [Vite](https://vitejs.dev/)con TypeScript già incluso.
0 commit comments