-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed
Description
Version
2.3.3
Reproduction link
https://jsfiddle.net/ianpatel/3bs145u7/
Steps to reproduce
var eventHub = new Vue()
Vue.component('foo', {
template: `<div>I'm foo <button @click="emit">Emit {{ value }}</button></div>`,
data: function() {
return {
value: 22
}
},
methods: {
emit() {
var newVal = eventHub.$emit('makeTwice', this.value)
// I'm expecting newVal will be 44 but it is object of Vue$3
alert(newVal)
// Please check into Console log
console.log(newVal)
this.value = newVal // Check console log, can not Convert
}
}
})
new Vue({
el: '#app',
data: function() {
return {}
},
mounted() {
eventHub.$on('makeTwice', this.makeTwice)
},
methods: {
makeTwice(val) {
return val * 2
}
}
})
What is expected?
I'm trying to Call other component method using single event hub var eventHub = new Vue()
, but I would like to get a return value from other component method.
https://vuejs.org/v2/guide/migration.html#dispatch-and-broadcast-replaced
What is actually happening?
Currently eventHub.$emit('makeTwice', this.value)
returning object of Vue$3. but component method return a value.
Vue$3 {_uid: 0, _isVue: true, $options: Object, _renderProxy: Proxy, _self: Vue$3…}
Am I missing something in https://vuejs.org/v2/api/#vm-emit.
vm.$emit( event, […args] )
do not have any return; It may possible, I'm expecting return value but $emit do not return method's return value.
Metadata
Metadata
Assignees
Labels
No labels