<template>
<div>
<div id='test' ref="test"></div>
</div>
</template>
<script>
export default {
mounted(){
window.onload = ()=>{
this.getHeight
}
window.onresize = ()=>{
this.getHeight
}
},
methods: {
getHeight(){
return document.getElementByID('test').offsetHeight // 获取高度为具体数值
//return document.getElementByID('test').style.height // 获取高度为空字符串""
//return this.$refs.test.offsetHeight // 普通vue对象
//return this.$refs.test.$el.offsetHeight // 如果是iview对象
}
}
</script>
<style>
#test{
height: 100%;
}
</style>
转载于:https://my.oschina.net/fyzhu/blog/3058714