-
Notifications
You must be signed in to change notification settings - Fork 4
/
ResizeObserver.js
38 lines (37 loc) · 1.03 KB
/
ResizeObserver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
export default {
name: 'resize',
abstract: true,
props: {
},
data () {
return {
_observer: null
}
},
created () {
if ('ResizeObserver' in window) {
this.$data._observer = new ResizeObserver((entries) => { // eslint-disable-line no-undef
this.$emit('resize', [entries[0]])
})
} else {
console.warn('[✋ VueObservables] You need to polyfill ResizeObserver')
}
},
mounted () {
this.$nextTick(() => {
if (this.$slots.default && this.$slots.default.length > 1) {
console.warn('[✋ VueObservables] You may only wrap one element in a <resize> component.')
} else if (!this.$slots.default || this.$slots.default.length < 1) {
console.warn('[✋ VueObservables] You must have one child inside a <resize> component.')
return
}
this.$data._observer.observe(this.$slots.default[0].elm)
})
},
destroyed () {
this.$data._observer.disconnect()
},
render () {
return this.$slots.default ? this.$slots.default[0] : null
}
}