Skip to content
Advertisement

Separate Array push in Vuejs

I am trying to get value from object and push into array using Vue. I wanted to separate every value when into different array every time I click my item. Every time I click todo should be push on different array, how I can separate to push into different array

JavaScript
JavaScript

Advertisement

Answer

Quick fix

One solution is to change mytodos into an array of 2 arrays (one for each TODO list):

JavaScript

Then, update your click-handler to pass the specific array element of mytodos along with the todo item to be added:

JavaScript

And update myClickTodo to handle these new arguments:

JavaScript

JavaScript
JavaScript

Components

A cleaner solution is to encapsulate the TODO list into a reusable component (e.g., named “my-list”):

JavaScript

…which would allow you to simplify your app template to this:

JavaScript

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