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
Post a Comment