Reputation: 1531
Why does my code for watching an object prop not work in vuejs?
I have browsed other Q/A posts about this issue and have not found a solution that works for me.
In my child component, I have am watching the filters prop like this...
export default {
name: "ChildComponent",
props: ["list", "searchTerms", "filters"]
watch: {
filters: {
deep: true,
handler: () => {
console.log("filter updated");
if (this.voterLayerActive) {
this.fetchBoundaryBox();
this.createMapWithLeafletAndMapTiler();
}
}
}
In my parent component, I am passing the filters prop like this...
<template> ...<ContactsMap :filters="f"></ContactsMap> ...</template>
<script>
...
export default {
name: "ParentComponent",
data() {
return {
f: {},
...
....
</script>
Upvotes: 0
Views: 242
Reputation: 2477
Try to replace your watch handler arrow function with:
watch: {
filters: {
deep: true,
handler(){
console.log("filter updated");
if (this.voterLayerActive) {
this.fetchBoundaryBox();
this.createMapWithLeafletAndMapTiler();
}
}
}
Upvotes: 1