Karlom
Karlom

Reputation: 14874

How to get text value of a clicked item in vue.js?

Here is the code:

<li v-for="u in usersList">
    <strong><a class="username" @click="openChatbox">${ u } </a></strong>
</li>

and the handling method:

openChatbox: function() {
    target = event.target || event.srcElement;
     this.isOpen = !this.isOpen;
     this.recepient = target.innerHTML
}, 

The problem is that this method sets recepientlike <strong>noob</strong> when u value is noob. How can I get only noob?

Upvotes: 5

Views: 3716

Answers (1)

Saurabh
Saurabh

Reputation: 73659

You can pass the user like following in the method:

<li v-for="u in usersList">
    <strong><a class="username" @click="openChatbox(u)">${ u } </a></strong>
</li>

and use it in method like this:

openChatbox: function(user) {
   //use user here
}, 

Upvotes: 8

Related Questions