凤凰求蛊
css-element-queries比较成熟的解决方案当然更简单的可以自己写个指令进行轮询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 id="canvas-wrap" v-resize="redraw">
<canvas></canvas></div>这样轮询到div的width,height发生变化就会触发redraw事件了,directive是随手写的,测了下有效,没实用过,只提供个思路