0👍
✅
Try wrapping the compute height code in nextTick like so:
data() {
return {
frameHeight: '',
};
},
mounted() {
this.$nextTick(() => {
window.addEventListener('load', () => {
this.frameHeight =
this.$refs.iframe.contentWindow.document.body.scrollHeight + 'px';
});
})
},
This should allow the elements to load before executing the code to grab height.
-1👍
You won’t need the eventListener when using nextTick. You can just do it like:
data() {
return {
frameHeight: '',
};
},
mounted() {
this.$nextTick(() => {
this.frameHeight =
this.$refs.iframe.contentWindow.document.body.scrollHeight + 'px';
});
},
Source:stackexchange.com