【问题标题】:Vue Filtering and PaginationVue过滤和分页
【发布时间】:2020-12-10 15:38:09
【问题描述】:

如何在 Vue 分页中根据选定的数字(例如 10、15 或 25)渲染一定数量的数组对象?我试过每页渲染 10 个项目,效果很好。

【问题讨论】:

    标签: javascript html vue.js html-table axios


    【解决方案1】:

    您可以创建一个对数组进行切片的计算属性,并在使用v-for 迭代数组时使用此计算属性:

    var app = new Vue({
      el: '#app',
      data: {
        items: [
          { id: 1, name: 'Foo' },
          { id: 2, name: 'Bar' },
          { id: 3, name: 'Baz' }
        ],
        amountOfItemsShown: 2,
      },
      computed: {
        slicedItems() {
          return this.items.slice(0, this.amountOfItemsShown);
        }
      }
    })
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
    
    
    <div id="app">
      
      <p>Amount of items shown: <input type="range" :min="1" :max="3" v-model="amountOfItemsShown"> <strong>{{ amountOfItemsShown }}</strong></p>
      <div v-for="item in slicedItems" :key="item.id">
        {{ item.name }}
      </div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-11
      • 2015-08-12
      • 2019-08-17
      • 2012-08-28
      • 2021-03-14
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多