javascript - vue.js - Add new value to object after click -


i have similar this:

arr = [   { val1: a, val2: b },   { val1: a, val2: b },   { val1: a, val2: b }  ]  <div v-for="single in arr">   <button v-on:click="addsome"></button> </div> 

and when click example second button in loop, want add 'val3': 'c' clicked object. tried $add, $set, , tried pass current 'single' , $index... , nothing. correct way add/edit specified object loop? sorry english ;) thank in advance

try this:

<div v-for="single in arr">   <button v-on:click="addsome($index)"></button> </div> 

and then

... "addsome": function (index) {     vue.set(this.arr[index], "val3", "c"); } ... 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -