Answer the question
In order to leave comments, you need to log in
How to catch change (get old props and new one) in Vue?
The task is as follows - you need to execute the 'handleChangeTitle' method when changing a certain props ('title').
How to do it? In updated(), I can’t execute it, because it will trigger other props on any state change.
I would like an option similar to the one in React -
componentWillReceiveProps(nextProps) {
//тут сравниваем nextProps.title и this.props.title
if(nextProps.title !== this.props.title) {
this.handleChangeTitle()
}
Answer the question
In order to leave comments, you need to log in
Try like this:
watch: {
title(newVal, oldVal) {
if(newVal !== oldVal) {
this.handleChangeTitle()
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question