Skip to content

Instantly share code, notes, and snippets.

@k1-c
Last active February 15, 2023 06:11
Show Gist options
  • Select an option

  • Save k1-c/ccc8ee4cc8b0bcc8080b5482e170935f to your computer and use it in GitHub Desktop.

Select an option

Save k1-c/ccc8ee4cc8b0bcc8080b5482e170935f to your computer and use it in GitHub Desktop.
[vue] [nuxt] [component] Vue Simple Accordion
<template>
<transition
name="slide"
@before-enter="(el) => (el.style.height = '0')"
@enter="(el) => (el.style.height = el.scrollHeight + 'px')"
@before-leave="(el) => (el.style.height = el.scrollHeight + 'px')"
@leave="(el) => (el.style.height = '0')"
>
<div v-if="isOpened" class="slide-body">
<slot />
</div>
</transition>
</template>
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
props: {
isOpened: {
type: Boolean,
required: true,
},
},
})
</script>
<style>
.slide-body {
overflow: hidden;
transition: 120ms ease-out;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment