vue 监听元素高度的变化_vue怎么监听元素尺寸变化?
当然更简单的可以自己写个指令进行轮询Vue.directive('resize',{bind(el,binding){letwidth='',height='';functionget(){conststyle=document.defaultView.getComputedStyle(el);if(width...
·
当然更简单的可以自己写个指令进行轮询Vue.directive('resize', {
bind(el, binding) { let width = '', height = ''; function get() { const style = document.defaultView.getComputedStyle(el); if (width !== style.width || height !== style.height) {
binding.value({width, height});
}
width = style.width;
height = style.height;
}
el.__vueReize__ = setInterval(get, 200);
},
unbind(el) {
clearInterval(el.__vueReize__);
},
});
使用方式
这样轮询到div的width,height发生变化就会触发redraw事件了,directive是随手写的,测了下有效,没实用过,只提供个思路
更多推荐
已为社区贡献1条内容
所有评论(0)