2

I've quite new to Vue.js, only started experimenting with it two days ago - so apologies if this is a dumb question.

I have a list and I would like to set a limit on how many objects should be returned to the list. I created a custom filter:

Vue.filter('limit', function (value, number) {
    for(var i = 0; i < number; i++){
        return value;
    }
});

And applied it:

<div class="project col-lg-4" v-repeat="projects | limit 3">

Yet nothing seems to change. I am aware that I could perform the limitation just using some extra js, but it would be nice to achieve this with a filter. Any help?

1 Answer 1

2

You should use a filter with v-repeat:

Vue.filter('limit', function (array, limit)
{
     return array.slice(0, limit);
});

and simply use it like so:

<li v-repeat="products | limit 3">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.