Vue seems to lack a method for pinpointing which property has changed.
Using the example provided triggers the watch callback whenever any property changes.
However, Vue does offer another option:
// keypath
vm.$watch('a.b.c', function (newVal, oldVal) {
// perform some action
})
https://v2.vuejs.org/v2/api/#vm-watch
In your scenario, it might look something like this:
data(){
return {
user:{
first_name:'',
last_name:'',
}
}
},
watch:{
"user.first_name": function(newVal, oldVal) {
// do something
},
"user.last_name": function(newVal, oldVal) {
// do something
}
}
Although I'm unsure if this is the most effective approach
Update from Vue documentation
Note: when mutating (instead of replacing) an Object or an Array, the
old value will be the same as the new value because they point to the
same Object/Array. Vue doesn't store a copy of the pre-mutate value.
Manually comparing objects in this case is futile since newVal = oldVal (same reference)
Update 2: Creating a new object may serve as a workaround
// for instance
user = Object.assign({}, user, { first_name: "newValOfFirstName" })
// instead of
user.first_name = "newValOfFirstName";