naive-ui/packages/transition/FadeInHeightExpandTransition.vue

59 lines
1.4 KiB
Vue
Raw Normal View History

2019-10-12 13:18:34 +08:00
<script>
export default {
props: {
transitionDisabled: {
type: Boolean,
default: false
}
},
beforeDestroy () {
if (this.transitionDisabled) {
const parent = this.$el.parentElement
if (parent) parent.removeChild(this.$el)
}
},
methods: {
handleBeforeLeave () {
this.$el.style.maxHeight = this.$el.offsetHeight + 'px'
this.$el.style.height = this.$el.offsetHeight + 'px'
this.$el.getBoundingClientRect()
},
handleLeave () {
// debugger
this.$el.style.maxHeight = 0
this.$el.getBoundingClientRect()
},
2019-12-09 19:16:03 +08:00
handleAfterLeave () {
this.$emit('after-leave')
},
2019-10-12 13:18:34 +08:00
handleEnter () {
this.$nextTick().then(() => {
this.$el.style.height = this.$el.offsetHeight + 'px'
this.$el.style.maxHeight = 0
this.$el.getBoundingClientRect()
this.$el.style.maxHeight = this.$el.style.height
})
},
handleAfterEnter () {
this.$el.style.height = null
this.$el.style.maxHeight = null
}
},
render (h) {
return h('transition', {
props: {
name: 'n-fade-in-height-expand'
},
on: {
beforeLeave: this.handleBeforeLeave,
leave: this.handleLeave,
enter: this.handleEnter,
2019-12-09 19:16:03 +08:00
afterEnter: this.handleAfterEnter,
afterLeave: this.handleAfterLeave
2019-10-12 13:18:34 +08:00
}
}, this.$slots.default)
}
}
</script>