I have a specific element that is conditionally rendered using v-if="isLogged"
when a user is logged in:
<div
v-if="isLogged"
class="chatBlock"
ref="chat"
></div>
The issue I'm facing is trying to retrieve the scroll height of the chat
reference within the mounted()
function - specifically using this.$refs.logged.scrollHeight
. However, this proves to be challenging because if a user is not logged in, the div
will not be rendered during the mounting stage. Consequently, even if a user logs in afterward, it won't work as the mounted stage has already passed.
Is there a way to monitor the appearance of an element in the DOM by utilizing the watch
method?
UPDATE
In response to Steven's suggestion below, I have incorporated a watcher in the mounted()
:
this.$store.watch(
(state) => {
return this.$store.getters.isLogged
},
(newValue, oldValue) => {
if (newValue) {
this.chatHeight = this.$refs.chat.scrollHeight
}
}
)