Skip to content

Commit 5d2a1e3

Browse files
Update transitions-enterleave.md (#581)
* fix: remove references to old versions of Vue 2 * fix: comment out TODOs * fix: update references to v-enter and v-leave * fix: update an example to match the CodePen * fix: correct typos * fix: introduce some articles to improve the flow * fix: migrate an example to Vue 3
1 parent 1cfbca4 commit 5d2a1e3

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

src/guide/transitions-enterleave.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ When an element wrapped in a `transition` component is inserted or removed, this
7575

7676
There are six classes applied for enter/leave transitions.
7777

78-
1. `v-enter-from`: Starting state for enter. Added before element is inserted, removed one frame after element is inserted.
78+
1. `v-enter-from`: Starting state for enter. Added before the element is inserted, removed one frame after the element is inserted.
7979

80-
2. `v-enter-active`: Active state for enter. Applied during the entire entering phase. Added before element is inserted, removed when transition/animation finishes. This class can be used to define the duration, delay and easing curve for the entering transition.
80+
2. `v-enter-active`: Active state for enter. Applied during the entire entering phase. Added before the element is inserted, removed when the transition/animation finishes. This class can be used to define the duration, delay and easing curve for the entering transition.
8181

82-
3. `v-enter-to`: **Only available in versions 2.1.8+.** Ending state for enter. Added one frame after element is inserted (at the same time `v-enter` is removed), removed when transition/animation finishes.
82+
3. `v-enter-to`: Ending state for enter. Added one frame after the element is inserted (at the same time `v-enter-from` is removed), removed when the transition/animation finishes.
8383

8484
4. `v-leave-from`: Starting state for leave. Added immediately when a leaving transition is triggered, removed after one frame.
8585

86-
5. `v-leave-active`: Active state for leave. Applied during the entire leaving phase. Added immediately when leave transition is triggered, removed when the transition/animation finishes. This class can be used to define the duration, delay and easing curve for the leaving transition.
86+
5. `v-leave-active`: Active state for leave. Applied during the entire leaving phase. Added immediately when a leave transition is triggered, removed when the transition/animation finishes. This class can be used to define the duration, delay and easing curve for the leaving transition.
8787

88-
6. `v-leave-to`: **Only available in versions 2.1.8+.** Ending state for leave. Added one frame after a leaving transition is triggered (at the same time `v-leave` is removed), removed when the transition/animation finishes.
88+
6. `v-leave-to`: Ending state for leave. Added one frame after a leaving transition is triggered (at the same time `v-leave-from` is removed), removed when the transition/animation finishes.
8989

9090
![Transition Diagram](/images/transitions.svg)
9191

@@ -153,7 +153,7 @@ CSS animations are applied in the same way as CSS transitions, the difference be
153153
Here's an example, omitting prefixed CSS rules for the sake of brevity:
154154

155155
```html
156-
<div id="example-2">
156+
<div id="demo">
157157
<button @click="show = !show">Toggle show</button>
158158
<transition name="bounce">
159159
<p v-if="show">
@@ -189,7 +189,7 @@ Vue.createApp(Demo).mount('#demo')
189189
transform: scale(0);
190190
}
191191
50% {
192-
transform: scale(1.5);
192+
transform: scale(1.25);
193193
}
194194
100% {
195195
transform: scale(1);
@@ -210,10 +210,10 @@ You can also specify custom transition classes by providing the following attrib
210210

211211
- `enter-from-class`
212212
- `enter-active-class`
213-
- `enter-to-class` (2.1.8+)
213+
- `enter-to-class`
214214
- `leave-from-class`
215215
- `leave-active-class`
216-
- `leave-to-class` (2.1.8+)
216+
- `leave-to-class`
217217

218218
These will override the conventional class names. This is especially useful when you want to combine Vue's transition system with an existing CSS animation library, such as [Animate.css](https://daneden.github.io/animate.css/).
219219

@@ -261,9 +261,7 @@ However, in some cases you may want to have both on the same element, for exampl
261261

262262
### Explicit Transition Durations
263263

264-
TODO: validate and provide an example
265-
266-
> New in 2.2.0+
264+
<!-- TODO: validate and provide an example -->
267265

268266
In most cases, Vue can automatically figure out when the transition has finished. By default, Vue waits for the first `transitionend` or `animationend` event on the root transition element. However, this may not always be desired - for example, we may have a choreographed transition sequence where some nested inner elements have a delayed transition or a longer transition duration than the root transition element.
269267

@@ -347,7 +345,7 @@ methods: {
347345

348346
These hooks can be used in combination with CSS transitions/animations or on their own.
349347

350-
When using JavaScript-only transitions, **the `done` callbacks are required for the `enter` and `leave` hooks**. Otherwise, the hooks will be called synchronously and the transition will finish immediately. Adding `:css="false"` will also let know Vue to skip CSS detection. Aside from being slightly more performant, this also prevents CSS rules from accidentally interfering with the transition.
348+
When using JavaScript-only transitions, **the `done` callbacks are required for the `enter` and `leave` hooks**. Otherwise, the hooks will be called synchronously and the transition will finish immediately. Adding `:css="false"` will also let Vue know to skip CSS detection. Aside from being slightly more performant, this also prevents CSS rules from accidentally interfering with the transition.
351349

352350
Now let's dive into an example. Here's a JavaScript transition using [GreenSock](https://greensock.com/):
353351

@@ -450,7 +448,7 @@ We discuss [transitioning between components](#transitioning-between-components)
450448

451449
It's actually possible to transition between any number of elements, either by using multiple `v-if`s or binding a single element to a dynamic property. For example:
452450

453-
TODO: rewrite example and put in codepen example
451+
<!-- TODO: rewrite example and put in codepen example -->
454452

455453
```html
456454
<transition>
@@ -537,7 +535,7 @@ Now let's update the transition for our on/off buttons with `out-in`:
537535

538536
With one attribute addition, we've fixed that original transition without having to add any special styling.
539537

540-
We can use this to coordinate more expressive movement, such as a folding card, as demonstrated below. It's actually two elements transitioning between eachother, but since the beginning and end states are scaling the same: horizontally to 0, it appears like one fluid movement. This type of slight-of-hand can be very useful for realistic UI microinteractions:
538+
We can use this to coordinate more expressive movement, such as a folding card, as demonstrated below. It's actually two elements transitioning between each other, but since the beginning and end states are scaling the same: horizontally to 0, it appears like one fluid movement. This type of sleight-of-hand can be very useful for realistic UI microinteractions:
541539

542540
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="result" data-user="Vue" data-slug-hash="76e344bf057bd58b5936bba260b787a8" data-preview="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Transition Modes Flip Cards">
543541
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/76e344bf057bd58b5936bba260b787a8">
@@ -550,19 +548,22 @@ We can use this to coordinate more expressive movement, such as a folding card,
550548

551549
Transitioning between components is even simpler - we don't even need the `key` attribute. Instead, we wrap a [dynamic component](component-basics.html#dynamic-components):
552550

553-
TODO: update to Vue 3
554-
555551
```html
556-
<transition name="component-fade" mode="out-in">
557-
<component :is="view"></component>
558-
</transition>
552+
<div id="demo">
553+
<input v-model="view" type="radio" value="v-a" id="a"><label for="a">A</label>
554+
<input v-model="view" type="radio" value="v-b" id="b"><label for="b">B</label>
555+
<transition name="component-fade" mode="out-in">
556+
<component :is="view"></component>
557+
</transition>
558+
</div>
559559
```
560560

561561
```js
562-
new Vue({
563-
el: '#transition-components-demo',
564-
data: {
565-
view: 'v-a'
562+
const Demo = {
563+
data() {
564+
return {
565+
view: 'v-a'
566+
}
566567
},
567568
components: {
568569
'v-a': {
@@ -572,18 +573,21 @@ new Vue({
572573
template: '<div>Component B</div>'
573574
}
574575
}
575-
})
576+
}
577+
578+
Vue.createApp(Demo).mount('#demo')
576579
```
577580

578581
```css
579582
.component-fade-enter-active,
580583
.component-fade-leave-active {
581584
transition: opacity 0.3s ease;
582585
}
583-
.component-fade-enter, .component-fade-leave-to
584-
/* .component-fade-leave-active below version 2.1.8 */ {
586+
587+
.component-fade-enter-from,
588+
.component-fade-leave-to {
585589
opacity: 0;
586590
}
587591
```
588592

589-
TODO: example
593+
<!-- TODO: codepen -->

0 commit comments

Comments
 (0)