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
Earlier, we used the `is`attribute to switch between components in a tabbed interface:
7
+
まず、`is`属性を利用してタブインタフェースのコンポーネントを切り替えることができます:
8
8
9
9
```vue-html
10
10
<component :is="currentTabComponent"></component>
11
11
```
12
12
13
-
When switching between these components though, you'll sometimes want to maintain their state or avoid re-rendering for performance reasons. For example, when expanding our tabbed interface a little:
You'll notice that if you select a post, switch to the _Archive_tab, then switch back to _Posts_, it's no longer showing the post you selected. That's because each time you switch to a new tab, Vue creates a new instance of the `currentTabComponent`.
Recreating dynamic components is normally useful behavior, but in this case, we'd really like those tab component instances to be cached once they're created for the first time. To solve this problem, we can wrap our dynamic component with a `<keep-alive>`element:
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`method:
As you can see, this method accepts a factory function returning a `Promise`. 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.
Async components are _suspensible_by default. This means if it has a [`<Suspense>`](TODO)in the parent chain, it will be treated as an async dependency of that `<Suspense>`. In this case, the loading state will be controlled by the `<Suspense>`, and the component's own loading, error, delay and timeout options will be ignored.
The async component can opt-out of `Suspense` control and let the component always control its own loading state by specifying `suspensible: false`in its options.
0 commit comments