Answer the question
In order to leave comments, you need to log in
Split array into vuejs arrays?
Hi all!
Tell me how to split one array into different arrays in vue, provided:
1. the array can consist of n-number of objects;
2. objects in the array do not have cyclicity;
3. each object has a bunch of data and type_id , which can be either 0 or 1 ; Based on this condition, there should be two arrays.
list: [{..., ..., type_id: 0, ..., ..., }, {..., ..., type_id: 0, ..., ..., }, {..., ..., type_id: 0, ..., ..., }, {..., ..., type_id: 1,..., ..., }, ..., ..., ]
<my-component тут условия, если тип_ид === 0 />
. I don't know how best to do it. Tell me how to solve the problem?
Answer the question
In order to leave comments, you need to log in
If the two new arrays are intended to be used independently, then two computed properties must be created. And then a simple filter to sort through all the elements:
{
computed: {
id1() {
return this.list.filter(i => i.type_id === 1)
},
id0() {
return this.list.filter(i => i.type_id === 0)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question