Answer the question
In order to leave comments, you need to log in
How to get the value of a variable in watch in vue?
I created a notification component, which receives an array of messages, they are displayed, and after N - time they are deleted, here is the code:
export default {
props: {
notifications: {
type: Array
}
},
methods: {
removeNotification () {
setTimeout(() => {
this.notifications.pop()
}, 3000)
}
},
computed: {
notificationsLength () {
return this.notifications.length
}
},
watch: {
notificationsLength (newValue, oldValue) {
if (newValue > oldValue) this.removeNotification()
}
}
}
export default {
props: {
notifications: {
type: Array
}
},
methods: {
removeNotification () {
setTimeout(() => {
this.notifications.pop()
}, 3000)
}
},
watch: {
notifications (newValue, oldValue) {
if (newValue.length > oldValue.length) this.removeNotification()
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question