I
I
Igor2019-06-29 19:15:09
Vue.js
Igor, 2019-06-29 19:15:09

Vue callables or events?

Colleagues, is it correct to use "callbacks" to send events from child components.
I pass "callbacks" through "props".
I am attaching a diagram.
5d178c9cca569147316626.jpeg
In fact, the main idea is to create one
MainMenu component,
which, in turn, consists of several children, and children from children (I'm already exaggerating this).
At the moment, the depth of the hierarchy is 3 levels.
The child component of the List, the user will click on it.
The List then calls the parent's callable function, and so on.
Raise the event to the page and rejoice.
Questions!
To what extent is this correct?
What rake can be stepped on?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2019-06-29
@IgorPI

So, the solution is to "emit"
in the child element
In the parent

this.$on("on-main-menu-select-item", ({item}) => {
                    console.debug(item)
                })

This option also works
export default {
        name: "CardRows",
        components: {Card},
        props: {
            items: [],
            OnClickItem: Function
        },

        methods: {
        

            itemClick({id, name}){
                if (typeof this.OnClickItem === "function"){
                    this.OnClickItem({id, name})
                }
            }
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question