events
-
Type:
Object
-
Details:
An object where keys are events to listen for and values are the corresponding callbacks. Note these are Vue events rather than DOM events. The value can also be a string of a method name. The Vue instance will call
$on()
for each entry in the object at instantiation. -
Example:
var vm = new Vue({ events: { 'hook:created': function () { console.log('created!') }, greeting: function (msg) { console.log(msg) }, // can also use a string for methods bye: 'sayGoodbye' }, methods: { sayGoodbye: function () { console.log('goodbye!') } } }) // -> created! vm.$emit('greeting', 'hi!') // -> hi! vm.$emit('bye') // -> goodbye!
-
See also:
- Instance Methods - Events
- Parent-Child Communication
Please login to continue.