Skip to content
Advertisement

Vue add new value to array

I am new to VUE and for one project I am trying to update an array passing the object. I have two button which is called BUTTON 1 and BUTTON 2. If you click on BUTTON 1 then it will set an object to list[] using this.$set. But when BUTTON 2 is pressed it should update with the new value and should display as

JavaScript

Right now I am using this.$set for button 2 as well and it removes the previous value then adds the new one as {c:3} only. Is there a way to add on value using VUE to display { a:1,b:2,c:3} when BUTTON 2 is clicked.

View

JavaScript

Method

JavaScript

Below there is a jsfiddle link for my code

https://jsfiddle.net/ujjumaki/enj3dwo6/19/

Advertisement

Answer

Hope this works.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement