watch

watch

  • Type: Object

  • Details:

    An object where keys are expressions to watch and values are the corresponding callbacks. The value can also be a string of a method name, or an Object that contains additional options. The Vue instance will call $watch() for each entry in the object at instantiation.

  • Example:

    var vm = new Vue({
      data: {
        a: 1
      },
      watch: {
        'a': function (val, oldVal) {
          console.log('new: %s, old: %s', val, oldVal)
        },
        // string method name
        'b': 'someMethod',
        // deep watcher
        'c': {
          handler: function (val, oldVal) { /* ... */ },
          deep: true
        }
      }
    })
    vm.a = 2 // -> new: 2, old: 1
  • See also: Instance Methods - vm.$watch

doc_VueJS
2016-09-25 05:48:23
Comments
Leave a Comment

Please login to continue.