Currently tackling an issue in my Vue2 project related to a specific property I'm trying to watch.
Here's what the code snippet looks like:
watch: {
'car.wheels': function(){
...
}
Sometimes, 'wheels' is undefined
. Is there a way to set a default value for it?
I attempted to handle this by utilizing a computed property:
computed: {
wheels(){
return car.wheels ? car.wheels : somethingElse
}
},
watch: {
wheels: function(){
...
}
}
However, it seems that this solution doesn't always work as intended. The watcher does not update alongside the computed property, resulting in it still monitoring 'somethingElse' even when 'car.wheels' has a value.
Hopefully, this explanation was clear!
PS: Focusing on watching car
rather than wheels
is not feasible, given that 'car' receives frequent updates and involves substantial processing within the watcher.
PS 2: 'car' serves as a data store that I modify in another component.