带有 QPagination 组件和 laravel paginate() 方法的 Quasar QList 分页

Quasar QList pagination with QPagination component and laravel paginate() method

我想对使用 QList 组件制作的列表进行分页

使用 laravel paginate() 方法,我在客户端收到以下分页所需的数据:

current_page:
data:[]
first_page_url:
from:
last_page:
last_page_url:
next_page_url:
path:
per_page:
prev_page_url:
to:
total:

我刚开始使用 Quasar 框架,我想要一个简单的 QList 分页解决方案。

显然 QPagination 组件将适合此目的。

我将不胜感激关于如何实施有效的 QPagination 或其他简单解决方案的建议。

已编辑

一些代码来演示我正在努力实现的目标

<template>
  <q-page class="fit row wrap justify-center items-start content-start" style="overflow: hidden;">
        <div class="q-pa-md" style="width: 450px;"> 
            <q-list bordered separator v-for="(post, index) in posts" :key="index">              
              <q-item clickable v-ripple>
                  <q-item-section>
                        <q-item-label> {{ post.title }} | {{ index }}</q-item-label>
                        <q-item-label caption> {{ post.content }}</q-item-label>
                   </q-item-section>
              </q-item>

            </q-list>

            <div class="q-pa-lg flex flex-center">
                    <q-pagination
                          v-model="page"
                          :min="currentPage" 
                          :max="totalPages"
                          :input="true"
                          input-class="text-orange-10"
                    >
                    </q-pagination>
                </div>
          </div>
  </q-page>
</template>

<script>
export default {

   data() {
        return {
            posts : [{
                id: 1,
                title: "title one",
                content: "This is content one"
            },{
                id:2,
                title: "title two",
                content: "This is content two"
            },{
                id:3,
                title: "title three",
                content: "This is content three"
            }],

            page: 1,
            currentPage:0,
            nextPage: null,
            totalPages:5,
        }
   }
}
</script>

已编辑 » 为了更好地说明要解决的问题:

<template>
  <q-page class="fit row wrap justify-center items-start content-start" style="overflow: hidden;">
        <div class="q-pa-md" style="width: 450px;"> 
            <q-list bordered separator v-for="(post, index) in posts" :key="index">              
              <q-item clickable v-ripple>
                  <q-item-section>
                        <q-item-label> {{ post.title }} | {{ index }}</q-item-label>
                        <q-item-label caption> {{ post.content }}</q-item-label>
                   </q-item-section>
              </q-item>

            </q-list>

            <div class="q-pa-lg flex flex-center">
                    <q-pagination
                          v-model="page"
                          :min="currentPage" 
                          :max="totalPages"
                          :input="true"
                          input-class="text-orange-10"
                    >
                    </q-pagination>
                </div>
          </div>


        <div class="flex justify-center" >
            <button v-if="prevPage" class="text-grey-darker text-sm" style="margin-right:10px;" @click="goPrevPage(prevPage)">
                Prev. Page | Pag. {{currentPage}} of {{totalPages}}
            </button>
             <button  v-if="nextPage"  class="text-grey-darker text-sm" @click="goNextPage(nextPage)">
                Next Page | Pag. {{currentPage}} of {{totalPages}}
            </button>
         </div>


  </q-page>
</template>

<script>
export default {

   data() {
        return {
            posts : {},

             page: 0,
             currentPage:0,
             totalPages:null,
             totalPosts:0,
             nextPage: null,
             prevPage: null
        }
   },

   mounted() {
    this.getData();
   },

   methods:{
     getData(){
        this.$axios.get(`/listposts')
            .then((response) => {
                if (response.data.success) {

                   this.posts= response.data.posts.data;

                   this.page = response.data.posts.currentPage;
                   this.currentPage = response.data.posts.currentPage;
                   this.totalPages = response.data.posts.last_page;
                   this.totalPosts = response.data.posts.total;
                   this.page = response.data.posts.current_page;
                   this.nextPage = response.data.posts.next_page_url;
                   this.prevPage = response.data.posts.prev_page_url;

              } else { }
            })
            .catch(error => { 
          });
        }
     },

     goNextPage(urlNextPage){
        this.$axios.get(urlNextPage)
            .then((response) => {
                if (response.data.success) {

                   this.posts= response.data.posts.data;

                   this.page = response.data.posts.currentPage;
                   this.currentPage = response.data.posts.currentPage;
                   this.totalPages = response.data.posts.last_page;
                   this.totalPosts = response.data.posts.total;
                   this.page = response.data.posts.current_page;
                   this.nextPage = response.data.posts.next_page_url;
                   this.prevPage = response.data.posts.prev_page_url;

              } else { }
            })
            .catch(error => { 
          });
     }

     goPrevPage(urlPrevPage){
      this.$axios.get(urlPrevPage)
            .then((response) => {
                if (response.data.success) {

                   this.posts= response.data.posts.data;

                   this.page = response.data.posts.currentPage;
                   this.currentPage = response.data.posts.currentPage;
                   this.totalPages = response.data.posts.last_page;
                   this.totalPosts = response.data.posts.total;
                   this.page = response.data.posts.current_page;
                   this.nextPage = response.data.posts.next_page_url;
                   this.prevPage = response.data.posts.prev_page_url;

              } else { }
            })
            .catch(error => { 
          });
     }

   }
}
</script>

已编辑 有工作解决方案

<template>
  <q-page class="fit row wrap justify-center items-start content-start" style="overflow: hidden;">
        <div class="q-pa-md" style="width: 450px;"> 
            <q-list bordered separator v-for="(post, index) in posts" :key="index">              
              <q-item clickable v-ripple>
                  <q-item-section>
                        <q-item-label> {{ post.title }} | {{ index }}</q-item-label>
                        <q-item-label caption> {{ post.content }}</q-item-label>
                   </q-item-section>
              </q-item>

            </q-list>

            <div class="q-pa-lg flex flex-center">
                    <q-pagination
                          v-model="page"
                          :min="currentPage" 
                          :max="lastPage"
                          input
                          input-class="text-orange-10"
                          @input="goAnotherPage"
                    >
                    </q-pagination>
                </div>
          </div>
  </q-page>
</template>

<script>
export default {

   data() {
        return {
            posts : {},

            page: 0,
            currentPage:0,
            lastPage:0        
        }
   },

   mounted() {
    this.getData();
   },

   methods:{
     getData(){
        this.$axios.get('/listposts')
            .then((response) => {
                if (response.data.success) {
                   this.posts= response.data.posts.data;
                   this.page = response.data.posts.currentPage;
                   this.currentPage = response.data.posts.currentPage;
                   this.lastPage = response.data.posts.last_page;
              } else { }
            })
            .catch(error => { 
          });
        }
     },

    goAnotherPage(page) { 
      this.paginationUrl="http://my_app/api/listposts?page="+this.page;
      this.$axios.get(this.paginationUrl)
        .then((response) => {
            if (response.data.success) {
              this.posts= response.data.posts.data;
            } else { }
        })
            .catch(error => { 
     });
   }
}
</script>

只需使用计算 属性 基于分页获取数据。

    getData(){
        return  this.posts.slice((this.page-1)*this.totalPages,(this.page-1)*this.totalPages+this.totalPages)
    }

 <q-list bordered separator v-for="(post, index) in getData" :key="index">              
              <q-item clickable v-ripple>
                        <q-item-label> {{ post.title }} | {{ index }}</q-item-label>
                        <q-item-label caption> {{ post.content }}</q-item-label>
                   </q-item-section>
              </q-item>

            </q-list>

工作代码笔 - https://codepen.io/Pratik__007/pen/PowpOeL