mirror of
https://gitlab.com/bramw/baserow.git
synced 2024-11-21 23:37:55 +00:00
37 lines
963 B
JavaScript
37 lines
963 B
JavaScript
export const dimensionMixin = {
|
|
data() {
|
|
return {
|
|
dimensions: {
|
|
targetElement: null,
|
|
width: 1920,
|
|
height: 1080,
|
|
},
|
|
}
|
|
},
|
|
mounted() {
|
|
// Gives you time to set the targetElement in the mounted function of the component
|
|
// using this mixin
|
|
this.$nextTick(() => {
|
|
this.dimensions.targetElement = this.dimensions.targetElement || this.$el
|
|
this.resizeObserver = new ResizeObserver(this.updateElementSize)
|
|
this.resizeObserver.observe(this.dimensions.targetElement)
|
|
})
|
|
},
|
|
beforeDestroy() {
|
|
if (this.resizeObserver) {
|
|
this.resizeObserver.disconnect()
|
|
}
|
|
},
|
|
methods: {
|
|
updateElementSize(entries) {
|
|
for (const entry of entries) {
|
|
if (entry.target === this.dimensions.targetElement) {
|
|
const { width, height } = entry.contentRect
|
|
this.dimensions.width = width
|
|
this.dimensions.height = height
|
|
}
|
|
}
|
|
},
|
|
},
|
|
}
|