如何在Vue.js中实时获取元素的宽度和高度?以下是我的代码示例,请帮我修改以使其正常工作,谢谢!
请点击Codepen查看。
let app = new Vue({
el: '#app',
data: {
boxs: [{
width: 100,
height: 100
},
{
width: 100,
height: 100
}
]
}
});
#app {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
.resize {
display: flex;
justify-content: center;
align-items: center;
margin: 5px;
width: 100px;
height: 100px;
overflow: hidden;
resize: both;
background-color: #C3E2CE;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.4/vue.js"></script>
<div id="app">
<div v-for="box,key in boxs" class="resize">
{{ box.width }} x {{ box.height }}
</div>
</div>