I´m new to vue, and struggle with a - for me - strange behaviour.
I expected that every time a new "singleMessage" is inserted in the dom, the functions in "created" will be executed. But it doesn´t.
My goal is that every time a new single message is inserted - that works - after 5 seconds the function setMessageRead is called.
<div class="singleMessage" :class="{ unread: unread }">
<div class="messageData">
<span>{{ user }}</span> {{ timestamp | formatDate }}
</div>
<div class="messageContent">{{ text }} {{ uid }}</div>
</div>
</template>
<script>
export default {
name: "SingleMessage",
props: {
user: String,
text: String,
timestamp: Number,
channel: String,
unread: Boolean,
uid: Number,
},
created() {
setTimeout(() => {
this.setMessageRead(this.uid);
}, 5000);
},
methods: {
setMessageRead(key) {
this.$emit("update:unread", false);
},
},
};
</script>
<style>
.singleMessage.unread {
background: #fdfdc4;
}
</style>