papillon
papillon

Reputation: 2053

Watch one property with several handlers

Is there a way to watch a single property with several handlers?

I need it because I need some instructions to be immediate, and some others not. I guess the only solution for this is to create 2 watchers for the same property, if it is possible.

Something like this would be great, but this doesn't work since the first watcher on myProp is overriden:

watch: {
    myProp: {
        immediate: true,
        handler () {
            // instructions
        }
    },
    myProp() {
        // instructions
    }
}

Live test here

Upvotes: 1

Views: 107

Answers (1)

Roy J
Roy J

Reputation: 43881

You can add a watcher by calling vm.$watch. You might do that for the immediate one, in the created section, to be explicit about when it first fires.

Upvotes: 1

Related Questions