vm.$dispatch()

vm.$dispatch( event, […args] )

  • Arguments:

    • {String} event
    • [...args]
  • Usage:

    Dispatch an event, first triggering it on the instance itself, and then propagates upward along the parent chain. The propagation stops when it triggers a parent event listener, unless that listener returns true. Any additional arguments will be passed into the listener’s callback function.

  • Example:

    // create a parent chain
    var parent = new Vue()
    var child1 = new Vue({ parent: parent })
    var child2 = new Vue({ parent: child1 })
    
    parent.$on('test', function () {
      console.log('parent notified')
    })
    child1.$on('test', function () {
      console.log('child1 notified')
    })
    child2.$on('test', function () {
      console.log('child2 notified')
    })
    
    child2.$dispatch('test')
    // -> "child2 notified"
    // -> "child1 notified"
    // parent is NOT notified, because child1 didn't return
    // true in its callback
  • See also: Parent-Child Communication

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

Please login to continue.