Answer the question
In order to leave comments, you need to log in
How to get text inside a tag on click in Vue?
Good day everyone.
There is a code - in it a component and an instance.
How, when clicking on .b-list__item, to display the contents of this tag in the console or in some block, for example?
PS: I tried to do it with the v-on directive, but it turned out and did not show it, because I'm ashamed, because I'm new to vue.
Answer the question
In order to leave comments, you need to log in
print the contents of this tag to the console...
<li v-for="n in items" @click="onClick(n)">
{{ n.message }}
</li>
methods: {
onClick(item) {
console.log(item.message);
}
}
...or in some block
<li v-for="n in items" @click="$emit('select', n)">
{{ n.message }}
</li>
<b-list @select="selected = $event"></b-list>
<div v-if="selected">{{ selected.message }}</div>
data: () => ({
selected: null,
...
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question