[Vuejs]-How to add vote without refresh with vue.js?

0👍

Quick reading,

In vue, everything defined in data() is reactive, so you get auto-rendering and dynamic binding for free.

Here is an example, you can adapt it to your case.

https://jsfiddle.net/coligo/49gptnad/

<div id="vue-instance">
  <ul>
    <template v-for="com in comments">
      <li>
        <button @click="com.votes++">Upvote !</button>
        {{ com.votes }} - {{ com.subject }}
      </li>
    </template>
  </ul>
</div>

var vm = new Vue({
  el: '#vue-instance',
  data: {
    comments: [
        { votes: 0, subject: 'Yolo'},
    { votes: 0, subject: 'Kierkegaard rocked babe'}
    ]
  },
});

More on this : https://v2.vuejs.org/v2/guide/reactivity.html, check the docs, Evan You made an awesome work to make it look clear and nice.

Leave a comment