2022-02-11 11:03:15 +08:00
|
|
|
import { addResizeListener, removeResizeListener } from '@element-plus/utils'
|
2021-07-01 09:29:00 +08:00
|
|
|
|
2022-03-25 15:35:56 +08:00
|
|
|
import type { DirectiveBinding, ObjectDirective } from 'vue'
|
2021-09-09 19:41:10 +08:00
|
|
|
|
|
|
|
declare interface ResizeEl extends HTMLElement {
|
|
|
|
_handleResize?: () => void
|
|
|
|
}
|
2021-07-01 09:29:00 +08:00
|
|
|
|
|
|
|
const Resize: ObjectDirective = {
|
2021-09-09 19:41:10 +08:00
|
|
|
beforeMount(el: ResizeEl, binding: DirectiveBinding) {
|
2021-07-01 09:29:00 +08:00
|
|
|
el._handleResize = () => {
|
2021-09-04 19:44:11 +08:00
|
|
|
el && binding.value?.(el)
|
2021-07-01 09:29:00 +08:00
|
|
|
}
|
|
|
|
addResizeListener(el, el._handleResize)
|
|
|
|
},
|
2021-09-09 19:41:10 +08:00
|
|
|
beforeUnmount(el: ResizeEl) {
|
2021-07-01 09:29:00 +08:00
|
|
|
removeResizeListener(el, el._handleResize)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Resize
|