1
import { VNodeDirective } from 'vue/types/vnode'
2

3
interface ResizeVNodeDirective extends VNodeDirective {
4
  value?: () => void
5
  options?: boolean | AddEventListenerOptions
6
}
7

8 1
function inserted (el: HTMLElement, binding: ResizeVNodeDirective) {
9 1
  const callback = binding.value!
10 1
  const options = binding.options || { passive: true }
11

12 1
  window.addEventListener('resize', callback, options)
13 1
  el._onResize = {
14
    callback,
15
    options,
16
  }
17

18 1
  if (!binding.modifiers || !binding.modifiers.quiet) {
19 1
    callback()
20
  }
21
}
22

23 1
function unbind (el: HTMLElement) {
24 1
  if (!el._onResize) return
25

26 1
  const { callback, options } = el._onResize
27 1
  window.removeEventListener('resize', callback, options)
28 1
  delete el._onResize
29
}
30

31 1
export const Resize = {
32
  inserted,
33
  unbind,
34
}
35

36 1
export default Resize

Read our documentation on viewing source code .

Loading