我定义了
Parent
具有
Child
组件,这两个组件都具有动态转换,并将休假回调定义为
outro
,问题是
父母亲
组件被销毁
奥特罗
该方法运行良好,但其
小孩
组成部分
奥特罗
方法永远不会被激发。是否有办法做到这一点并保持
小孩
组件可重用和解耦?
Demo
.
应用程序模板:
<div id="app">
<parent v-if="showContainer"></parent>
<button @click="showContainer = !showContainer">
Toggle Container
</button>
</div>
Javascript:
// ISSUE:
// 1. Parent removes child component in its `outro` method
// 2. Child `outro` method never gets called
var Child = {
template: `
<transition
:css="false"
appear
@appear="intro"
@enter="intro"
@leave="outro"
>
<div class="Child"></div>
</transition>`,
methods: {
intro: function (el, done) {
TweenLite.fromTo(el, 0.5,
{ y: '100%' },
{ y: '0%', delay: 0.5, onComplete: done })
},
outro: function (el, done) {
// 2 <===
TweenLite.to(el, 0.5,
{ y: '100%', onComplete: done })
},
},
}
var Parent = {
template: `
<transition
:css="false"
appear
@appear="intro"
@enter="intro"
@leave="outro"
>
<div class="Parent">
<div ref="inner" class="Parent__inner"></div>
<child v-if="showChild"></child>
</div>
</transition>`,
components: {
Child: Child,
},
data() {
return {
showChild: true,
}
},
methods: {
intro: function (el, done) {
TweenLite.fromTo(this.$refs.inner, 0.5,
{ y: '100%' },
{ y: '0%', delay: 0.25, onComplete: done })
},
outro: function (el, done) {
// 1 <===
// Setting `showChild` to `false` should remove Child component
// and trigger its `outro` method ¿?
this.showChild = false
TweenLite.to(this.$refs.inner, 0.5,
{ y: '100%', delay: 0.25, onComplete: done })
},
},
}
new Vue({
el: '#app',
data() {
return {
showContainer: true,
}
},
components: {
Parent: Parent,
},
})