2022-02-11 11:03:15 +08:00
|
|
|
import { addResizeListener, removeResizeListener } from '@element-plus/utils'
|
2021-07-01 09:29:00 +08:00
|
|
|
|
2021-09-09 19:41:10 +08:00
|
|
|
import type { ObjectDirective, DirectiveBinding } from 'vue'
|
|
|
|
|
|
|
|
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
|