Last active
January 14, 2021 21:06
-
-
Save q42jaap/364ac40c8de3b1dabff2b0464aa2a739 to your computer and use it in GitHub Desktop.
TIL vue v3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div id="app"> | |
<expander v-slot="{isExpanded, toggle}" :initial-expanded="false"> | |
<dl> | |
<dt class="toggler" :class="{expanded: isExpanded}" v-on:click="toggle">Name</dt> | |
<dd v-if="isExpanded"> | |
Description | |
</dd> | |
</dl> | |
</expander> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<slot v-bind="{isExpanded, toggle}"></slot> | |
</template> | |
<script lang="ts"> | |
export default defineComponent({ | |
props: ['initialExpanded'], | |
data() { | |
return { | |
isExpanded: this.initialExpanded, | |
}; | |
}, | |
methods: { | |
toggle() { | |
this.isExpanded = !this.isExpanded; | |
}, | |
}, | |
}); | |
</script> | |
<style scoped lang="scss"> | |
// This can be scoped even though the class is set in the slot. | |
.toggler.expanded { | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment