vue + element ui项目遇到一个界面要求:
mounted() {
this.$nextTick(function() {
this.tableHeight = window.innerHeight - this.$refs.tableRef.$el.getBoundingClientRect().top - 137
// 监听窗口大小变化
// this.$refs.tableRef.$el.getBoundingClientRect().top:表格距离浏览器的高度
var that = this
window.onresize = function() {
that.tableHeight = window.innerHeight - that.$refs.tableRef.$el.getBoundingClientRect().top - 137
}
})
},
注:
this.$refs['通过设置ref获取到的dom元素'].getBoundingClientRect();
获取元素距离顶部的距离:
this.$refs.journalUpward.getBoundingClientRect().top
获取元素组件高度:
this.$refs.top.$el.offsetHeight
设置元素样式:
this.$refs.mask.style.top = 100 + 'px'