assembly/components/CustomTransition.vue

31 lines
830 B
Vue
Raw Permalink Normal View History

2021-07-26 22:19:20 +00:00
<template>
<transition
v-bind="$attrs"
v-on="$listeners"
@after-enter="addAfterEnterClass"
@before-leave="removeAfterEnterClass"
>
<slot />
</transition>
</template>
<script>
import { computed, defineComponent } from '@nuxtjs/composition-api'
export default defineComponent({
props: {
afterEnterClass: { type: String, default: '' },
},
setup(props) {
const afterEnterClasses = computed(() => props.afterEnterClass.split(' ').filter((cssClass) => !!cssClass))
function addAfterEnterClass(el) {
afterEnterClasses.value.forEach((cssClass) => el.classList.add(cssClass))
}
function removeAfterEnterClass(el) {
afterEnterClasses.value.forEach((cssClass) => el.classList.remove(cssClass))
}
return { addAfterEnterClass, removeAfterEnterClass }
},
})
</script>