S
S
shasoft2019-09-30 14:45:28
JavaScript
shasoft, 2019-09-30 14:45:28

How to pass an attribute to another component in Vue to use its value in your plugin?

There is a component. I am writing a plugin and I want to use the value from my attribute in someone else's component. It seems that I found in the Vue documentation that attributes can be passed, but either I didn’t understand what was meant, or I just can’t figure out how to get the value of this attribute in the plugin. I write like this

<v-text-field data-test="мой параметр"></v-text-field>

I output this component to the console, but I can't find this value "my parameter" anywhere

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shasoft, 2019-09-30
@shasoft

Thanks to all. I'm the idiot. The attribute was written in one component, and was looking for its value in another :(
If you write as in the example above
then this.$attrs component will have the attribute this.$attrs['data-test']="my parameter"

D
Dima Pautov, 2019-09-30
@bootd

You will not be able to transfer your props to the component that you have connected to the project as an npm package, because you do not have this component in the project itself, it lies in node_modules. If you want to add your own properties or logic to the component, copy the entire component from node_modules and transfer it to your components folder, and only then can you edit it and then use it.
Then plug it in and use

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question