X
X
xeywar2021-01-22 21:33:59
Vue.js
xeywar, 2021-01-22 21:33:59

Vue. How can a child component call the parent's props?

There is a parent component that can accept <slot />, and some props
How in <slot />(children), use methods (or props) of the parent component? If this can be implemented in Vue somehow and is the correct approach in general.

I write in react, you can override children there:

children = React.Children.toArray(children).map(child=> {
      return React.cloneElement(child, {
          active,
          _onChange: (value, label)=> onChange(value, label),
          ...child.props
      });
    });


Is there something similar in Vue, or am I digging somewhere in the wrong place? Maybe in Vue this approach is generally not appropriate and there is another way to use some kind of "general" props?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-01-22
@xeywar

You can reach the parent through this.$parent.
But I would beat my hands with a stick for it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question