filter - VueJS: how can i use two computed properties inside one v-for? -
i have computed property:
computed: { filteredcars: function() { var self = return self.carros.filter(function(carro) { return carro.nome.indexof(self.busca) !== -1 }) }, },
and i'm using v-for this:
<tr v-for="carro in filteredcars"> <td>{{carro.nome}}</td> <td>{{carro.marca}}</td> <td>{{carro.categoria}}</td> <td>{{carro.motor}}</td> <td>{{carro.cambio}}</td> <td>{{carro.preco}}</td> </tr>
but need create computed property limit data quantity, how call inside same v-for?
i'm trying use filteredcars + filter, in case 'limit' filter vue 1.x. i've done example using vue 1.x need using vue 2.x.
vue.filter('limit', function (value, amount) { return value.filter(function(val, index, arr){ return index < amount; }); <tr v-for="carro in carros | limit upperlimit> ... </tr>
just use array.prototype.slice
(array.prototype.splice
should work too) in computed property.
data: { carros: [...], upperlimit: 30 }, computed: { filteredcars: function() { const arr = this.carros.filter(function(carro) { return carro.nome.indexof(self.busca) !== -1 }); if (arr.length > this.upperlimit) { return arr.slice(0, this.upperlimit + 1); } return arr; }, }
Comments
Post a Comment