Skip to content

Instantly share code, notes, and snippets.

@iErik
Created April 16, 2019 17:10
Show Gist options
  • Select an option

  • Save iErik/89f24bce8f84dd27b6e68d79bd692cd7 to your computer and use it in GitHub Desktop.

Select an option

Save iErik/89f24bce8f84dd27b6e68d79bd692cd7 to your computer and use it in GitHub Desktop.
const Collapsible = (refName = 'contentWrapper') => ({
data: () => ({
hideContents: false,
contentObs: null,
contentHeight: 0,
}),
mounted () {
this.$nextTick(() => {
const el = this.$refs[refName].childNodes[0]
this.contentObs = new ResizeObserver(ev => {
const rect = ev[0].target.getBoundingClientRect()
this.contentHeight = rect.height
})
this.contentObs.observe(el)
})
},
beforeDestroy () {
this.contentObs.disconnect()
}
})
export default Collapsible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment