Vue
in mounted
, refs
cannot call
to height of element
< / H2 >
the requirement takes the height of the element after the page is loaded, and then assigns it to another elementafter calculation.
you can see that the top is fxied
, so it causes the lower text (the size of the top is uncertain and cannot be set directly through css
), so you need to load the page and get it and assign a value to the div
below
mounted() {
setTimeout(() => {
const heightA = window.getComputedStyle(this.$refs.header).height;
console.log("heightA ==> "+heightA);
}, 1000);
}
output 50px
the last one can be obtained, but it is not satisfied to get the height immediately after the page is loaded