K
K
kroha30002020-02-24 15:29:38
Vue.js
kroha3000, 2020-02-24 15:29:38

How to limit the output of a list in vuejs, for example 5th or 10th and so on?

There is a design, it displays a preview of the user's avatars:

<div class="conteaner-drop">
  <router-link :to="`/drop${ user.drop }`" class="drop-preview" v-for="user in randomList" :key="user">
    <img :src="require(`@/assets/images/dropuser/drop${ user.drop }/${ user.avatar }.jpg`)" />
    <div class="pfilter"></div>
    <span :class="user.status"></span>
     <p>{{ user.name }}</p>
   </router-link>
</div>


computed: {
  randomList: function(){
    return this.users.sort(function(){return 0.5 - Math.random()});
  }
}


In this option, all users that are in the array are displayed. (did not show the date with the array) How to limit the list? I poked around in the documentation, but all the list output restrictions are displayed in the example, through v-for, but here it is already there. How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-02-24
@kroha3000

computed: {
  randomList: function(){
    return this.shortList.sort(function(){return 0.5 - Math.random()});
  },

  shortList: function() {
    return this.users.slice(0, 5)
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question