Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue after $emit callback finished

Tags:

vue.js

emit

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;
        }
    }
like image 799
pdwjun Avatar asked Aug 31 '25 21:08

pdwjun


1 Answers

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.

like image 182
B. Fleming Avatar answered Sep 04 '25 05:09

B. Fleming