[Vuejs]-Vuejs data price total calculation

3👍

Define total as a computed property using reduce function as follows :

data: {
   userList: [...],
},
computed:{
  total(){
     return this.userList.reduce((acc,curr)=>{
         return acc+=(+curr)
       },0)
    }
 }

}

in template :

 <td>Total: {{total}}</td>

Leave a comment