diff --git a/src/.vuepress/config.js b/src/.vuepress/config.js index efb3d4788b..e544b0e452 100644 --- a/src/.vuepress/config.js +++ b/src/.vuepress/config.js @@ -197,6 +197,7 @@ const sidebar = { '/guide/migration/props-default-this', '/guide/migration/render-function-api', '/guide/migration/slots-unification', + '/guide/migration/suspense', '/guide/migration/transition', '/guide/migration/transition-group', '/guide/migration/v-on-native-modifier-removed', diff --git a/src/guide/migration/introduction.md b/src/guide/migration/introduction.md index d12365c8a6..95f58ae217 100644 --- a/src/guide/migration/introduction.md +++ b/src/guide/migration/introduction.md @@ -49,6 +49,7 @@ Some of the new features to keep an eye on in Vue 3 include: - [SFC Composition API Syntax Sugar (` +``` + +The `` component has two slots. Both slots only allow for one immediate child node. The node in the `default` slot is shown if possible. If not, the node in the `fallback` slot will be shown instead. + +Importantly, the async component doesn't need to be the immediate child of the ``. It can be at any depth within the component tree and doesn't need to appear in the same template as the `` itself. The content is only considered resolved once all descendants are ready. + +The other way to trigger the `fallback` slot is for a descendant component to return a promise from its `setup` function. This is typically implemented using `async` rather than explicitly returning a promise: + +```js{2} +export default { + async setup() { + // Be very careful using `await` inside `setup` as + // most Composition API functions will only work + // prior to the first `await` + const data = await loadData() + + // This is implicitly wrapped in a promise because + // the function is `async` + return { + // ... + } + } +} +``` + +## Child Updates + +Once a `` has resolved the contents of its `default` slot, it can only be triggered again if the `default` root node is replaced. New components nested deeper in the tree are not sufficient to move the `` back into a pending state. + +If the root node does change it will trigger the `pending` event. However, by default, it won't update the DOM to show the `fallback` content. Instead, it will continue to show the old DOM until the new components are ready. This can be controlled using the `timeout` prop. This value, expressed in milliseconds, tells the `` component how long to wait before showing the `fallback`. A value of `0` will show it immediately when the `` enters the pending state. + +## Events + +In addition to the `pending` event, the `` component also has `resolve` and `fallback` events. The `resolve` event is emitted when new content has finished resolving in the `default` slot. The `fallback` event is fired when the contents of the `fallback` slot are shown. + +The events could be used, for example, to show a loading indicator in front of the old DOM while new components are loading. + +## Combining with Other Components + +It is common to want to use `` in combination with the [``](/api/built-in-components.html#transition) and [``](/api/built-in-components.html#keep-alive) components. The nesting order of these components is important to get them all working correctly. + +In addition, these components are often used in conjunction with the `` component from [Vue Router](https://next.router.vuejs.org/). + +The following example shows how to nest these components so that they all behave as expected. For simpler combinations you can remove the components that you don't need: + +```html + + + +``` + +Vue Router has built-in support for [lazily loading components](https://next.router.vuejs.org/guide/advanced/lazy-loading.html) using dynamic imports. These are distinct from async components and currently they will not trigger ``. However, they can still have async components as descendants and those can trigger `` in the usual way.