mounted() {
this.$refs.index.style.paddingBottom = this.$refs.sus.clientHeight + 'px'
}
试着在mounted声明周期去获取某元素的高度,但是仍然获取到的是0,即使是DOMContentLoad 或者 window.onload 后仍然取不到。
那vue要什么时候才能获取dom的实际计算结果?
mounted() {
this.$refs.index.style.paddingBottom = this.$refs.sus.clientHeight + 'px'
}
试着在mounted声明周期去获取某元素的高度,但是仍然获取到的是0,即使是DOMContentLoad 或者 window.onload 后仍然取不到。
那vue要什么时候才能获取dom的实际计算结果?
绑定对应的事件就可以
methods:{
this.$nextTick(() => {
this.$refs.index.style.paddingBottom = this.$refs.sus.clientHeight + 'px';
})
}
试试看this.$nextTick
mounted (){
this.$nextTick(() => {
this.$refs.index.style.paddingBottom = this.$refs.sus.clientHeight + 'px';
});
}
就是在mounted的时候,如果你要获取的元素高度是动态由数据撑起来的需要使用
this.$nextTick
可测试上方代码。