vue动态获取div高度
<div v-resize="resize" id="first">
111111111111
</div>
<div id="second"></div>
<script>
directives: {
resize: {
bind (el, binding) {
let width = '', height = '';
function isReize () {
const style = document.defaultView.getComputedStyle(el);
if (width !== style.width || height !== style.height) {
binding.value();
}
width = style.width;
height = style.height;
}
el.__vueSetInterval__ = setInterval(isReize, 300);
},
unbind (el) {
clearInterval(el.__vueSetInterval__);
}
}
},
methods:{
resize () {
let height=document.getElementById("first").clientHeight
let body=document.getElementById("second")
body.style.marginTop=(height+50).toString()+"px"
},
}
</script>