L
L
Lawrence2022-01-05 18:36:12
Vue.js
Lawrence, 2022-01-05 18:36:12

How to access $root component when using Composition API?

Tell me how to correctly access the $root component when working with the Composition API ?
I found an ambiguous solution in the open spaces, it works on DEV, but when building in production it does not work.

Solution that only works in dev
const root = getCurrentInstance();
root.ctx.$root.bodyOverflow(true);

Just in case, I’ll explain why I turn to the root component, perhaps in general it’s not the right approach.
In the parent component, I have methods, handler pieces or properties that are very often used in other child components. As a rule, these are small pieces of code. And in order not to duplicate the same code in the components, I turn to the parent and call the one I need.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ice, 2022-01-06
@IceRD

You can pass parameters and methods as props
or use provide / inject

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question