pdwjun
pdwjun

Reputation: 133

vue after $emit callback finished

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;
        }
    }

Upvotes: 4

Views: 14507

Answers (1)

B. Fleming
B. Fleming

Reputation: 7220

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.

Upvotes: 8

Related Questions