C
C
Cyril2017-06-20 15:13:46
Vue.js
Cyril, 2017-06-20 15:13:46

How to get attribute values ​​in vue.js?

<ul>
<li v-for="post in posts | orderBy 'date' -1" 
     v-on:click="showId"
     :key="post.id">  // <!-- вот этого элемента -->
  <p>{{ post.date }}</p>
  <h3>{{ post.title }}</h3>
  <p>{{ post.description }}</p>
</li>
</ul>

...
methods: {
   showId: function (event) {					
      console.log("Получить атрибут key элемента, по которому кликнули") // <-- вот сюда											
   }
}
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2017-06-20
@njee

v-on:click="showId(post.id)"
...
   showId: function (key){					
      console.log(key) // <-- вот сюда											
   }

Or even
v-on:click="showId(post)"
...
   showId: function (post){					
      console.log(post.id) // <-- вот сюда											
   }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question