Vue cannot be called to the height of the element through refs in mounted

< H2 > 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 element
after calculation.

clipboard.png
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
Aug.05,2021

mounted just because the vue rendering has been completed does not mean that the styles in it have also been rendered.
when you are reading height, the page has not been rendered yet


get the height through this.$refs.header.offsetHeight to try


solve the problem? I also encountered whether I do not know when to finish loading

.
Menu