@@ -20,14 +20,14 @@ badges:
20
20
以前、非同期コンポーネントは Promise を返す関数としてコンポーネントを定義することで、このように簡単に作成されました:
21
21
22
22
``` js
23
- const asyncPage = () => import (' ./NextPage .vue' )
23
+ const asyncModal = () => import (' ./Modal .vue' )
24
24
```
25
25
26
26
または、オプション付きのさらに高度なコンポーネント構文として:
27
27
28
28
``` js
29
- const asyncPage = {
30
- component : () => import (' ./NextPage .vue' ),
29
+ const asyncModal = {
30
+ component : () => import (' ./Modal .vue' ),
31
31
delay: 200 ,
32
32
timeout: 3000 ,
33
33
error: ErrorComponent,
@@ -45,25 +45,29 @@ import ErrorComponent from './components/ErrorComponent.vue'
45
45
import LoadingComponent from ' ./components/LoadingComponent.vue'
46
46
47
47
// オプションなしの非同期コンポーネント
48
- const asyncPage = defineAsyncComponent (() => import (' ./NextPage .vue' ))
48
+ const asyncModal = defineAsyncComponent (() => import (' ./Modal .vue' ))
49
49
50
50
// オプション付きの非同期コンポーネント
51
- const asyncPageWithOptions = defineAsyncComponent ({
52
- loader : () => import (' ./NextPage .vue' ),
51
+ const asyncModalWithOptions = defineAsyncComponent ({
52
+ loader : () => import (' ./Modal .vue' ),
53
53
delay: 200 ,
54
54
timeout: 3000 ,
55
55
errorComponent: ErrorComponent,
56
56
loadingComponent: LoadingComponent
57
57
})
58
58
```
59
59
60
+ ::: tip NOTE
61
+ Vue Router は * 遅延読み込み* と呼ばれるルートコンポーネントを非同期に読み込む似たような仕組みをサポートしています。似てはいますが、この機能は Vue の非同期コンポーネントのサポートとは異なります。 Vue Router でルートコンポーネントを構成するときは、 ` defineAsyncComponent ` を ** 使用しない** 必要があります。これについては、 Vue Router のドキュメントの [ ルートの遅延読み込み] ( https://next.router.vuejs.org/guide/advanced/lazy-loading.html ) で詳しく説明されています。
62
+ :::
63
+
60
64
2.x からなされたもう一つの変更は、直接コンポーネント定義を提供できないことを正確に伝えるために ` component ` オプションの名前が ` loader ` に替わったことです。
61
65
62
66
``` js{4}
63
67
import { defineAsyncComponent } from 'vue'
64
68
65
- const asyncPageWithOptions = defineAsyncComponent({
66
- loader: () => import('./NextPage .vue'),
69
+ const asyncModalWithOptions = defineAsyncComponent({
70
+ loader: () => import('./Modal .vue'),
67
71
delay: 200,
68
72
timeout: 3000,
69
73
errorComponent: ErrorComponent,
0 commit comments