Skip to content

Commit 3e681ab

Browse files
committed
transition control
1 parent c7d0e17 commit 3e681ab

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

source/api/directives.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Example inheriting individual properties (using the same data):
200200
201201
### v-component
202202

203-
- Directive params: `keep-alive`
203+
- Directive params: `keep-alive`, `wait-for`, `transition-mode`
204204

205205
Compile this element as a child ViewModel with a registered component constructor. This can be used with `v-with` to inehrit data from the parent. For more details see [Component System](/guide/components.html).
206206

source/guide/components.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,54 @@ If you want to keep the switched-out components alive so that you can preserve i
281281
</div>
282282
```
283283

284+
### Transition Control
285+
286+
There are two additional attribute parameters that allows advanced control of how dynamic components should transition from one to another.
287+
288+
#### `wait-for`
289+
290+
An event name to wait for on the incoming child component before switching it with the current component. This allows you to wait for asynchronous data to be loaded before triggering the transition to avoid unwanted flash of emptiness in between.
291+
292+
**Example:**
293+
294+
``` html
295+
<div v-component="{{view}}" wait-for="data-loaded"></div>
296+
```
297+
``` js
298+
// component definition
299+
{
300+
// fetch data and fire the event asynchronously in the
301+
// compiled hook. Using jQuery just for example.
302+
compiled: function () {
303+
var self = this
304+
$.ajax({
305+
// ...
306+
success: function (data) {
307+
self.$data = data
308+
self.emit('data-loaded')
309+
}
310+
})
311+
}
312+
}
313+
```
314+
315+
#### `transition-mode`
316+
317+
By default, the transitions for incoming and outgoing components happen simultaneously. This param allows you to configure two other modes:
318+
319+
- `in-out`: New component transitions in first, current component transitions out after incoming transition has finished.
320+
- `out-in`: Current component transitions out first, new componnent transitions in after outgoing transition has finished.
321+
322+
**Example**
323+
324+
``` html
325+
<!-- fade out first, then fade in -->
326+
<div v-component="{{view}}"
327+
v-transition="fade"
328+
transition-mode="out-in">
329+
</div>
330+
```
331+
284332
## List and Components
285333

286334
For an Array of Objects, you can combine `v-component` with `v-repeat`. In this case, for each Object in the Array, a child ViewModel will be created using that Object as data, and the specified component as the constructor.

0 commit comments

Comments
 (0)