[Vuejs]-Vue watch nested object and each prop

0👍

Not 100% sure this is the correct answer but this would work. I don’t know if vue has any arguments that would directly support your case without using in if statement.

watch: {
        'input.source.location': {
            handler: () => {
                console.log("locations");
            }
        },
        'input': {
            handler: (newVal) => {
                if(newVal.source.location) return;
                console.log("all the rest");
            },
            deep: true
        }
    },

-OR-

watch: {
        'input': {
            handler: (newVal) => {
                if(newVal.source.location) console.log("locations");
                else console.log("all the rest");
            },
            deep: true
        }
    },

Leave a comment