A
A
Alexander2018-06-06 13:25:17
JavaScript
Alexander, 2018-06-06 13:25:17

How to access the data of the component in which it is used from a custom directive in vue.js?

It is necessary to get access from the custom directive to the name of the component - $options.name. Passing this value to each time the directive is called is not an option, since the purpose of the directive is to shorten certain logic.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2018-06-06
@bootd

Directives do not know how to work with components, because they know nothing about them and should not know. They were invented for something else, namely

to perform low-level operations on the DOM
quote from the docs
You can only work with the dom element to which the directive applies, no more.
Otherwise, there are mixins that are built directly into the component and can work inside it, getting the data they need from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question