In the compoent ,when call $emit('callback', params)
finished, I need the returned value. Someone can help?
vueComponent:
methods: {
test: function () {
if(this.$emit('cb', param1)){
// this not working
console.log('return true')
}else{
console.log('return false')
}
}
}
vueRoot:
methods: {
cb: function () {
return true;
}
}
As per my comment below the original question, $emit
only tells the parent component that an event has occurred and allows it to do something in response to the event and any data sent with it. The child component has no way of knowing what the results of the parent's actions are. In order to tell the child component something after the callback finishes, you will need to send that value through a prop
and have the child watch
for any changes to the prop's value.