Created
June 11, 2019 17:25
-
-
Save iErik/93865d2b7f2502b2def67f86d9cb1065 to your computer and use it in GitHub Desktop.
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
const Collapsible = (refName = 'contentWrapper') => ({ | |
data: () => ({ | |
hideContents: false, | |
contentObs: null, | |
contentHeight: 0, | |
}), | |
mounted () { | |
this.$nextTick(() => { | |
if (!this.$refs[refName]) return | |
this.contentObs = new ResizeObserver(ev => { | |
const rect = ev[0].target.getBoundingClientRect() | |
this.contentHeight = rect.height | |
}) | |
const el = this.$refs[refName].hasOwnProperty('$el') | |
? this.$refs[refName].el | |
: this.$refs[refName] | |
if (el) this.contentObs.observe(el.childNodes[0]) | |
}) | |
}, | |
beforeDestroy () { | |
if (this.contentObs) this.contentObs.disconnect() | |
} | |
}) | |
export default Collapsible |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment