S
S
Sketch0072022-04-03 20:18:54
JavaScript
Sketch007, 2022-04-03 20:18:54

How to pass a function to a component through a parent in vue.js?

The pages have a trace. structure:

Parent, file - Vue.js Children
, components -

<page-header>
<page-content>
<page-footer>


Buttons intended specifically for the current page are drawn in the header, and by clicking on them, a function that already exists in page-content should be executed, or a function should be passed to the page content.

(for example, opening the chat settings) I

managed to connect these two components, I can pass any test values, but I just can’t figure out how to pass/call the function content must have the same header, but with different buttons

6249d4b0b82b6214635578.jpeg


Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2022-04-03
@Sketch007

I would build in a different way. Each page is a separate component, switched via vue-router. The description of the buttons is passed to the header. When the button is clicked, the header generates an event with the button ID. The page processes the event, receives new data and passes it to the content.

<page-following>
  <page-header
    title="Following"
    :buttons="buttons"
    @buttonPressed="onButtonPressed"
  />
  <!-- здесь контент -->
  <page-footer />
</page-following>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question