【问题标题】:Get current page in vuejs在 vuejs 中获取当前页面
【发布时间】:2021-07-14 08:03:32
【问题描述】:

在 vue 中我处理代码:

<b-pagination
  :total-rows="props.total"
  first-number
  last-number
  align="right"
  prev-class="prev-item"
  next-class="next-item"
  class="mt-1 mb-0"
  @input="changePage"
  >
</b-pagination>

这是一个分页示例:

>

methods: {
    changePage() {
         //get current page
    }
}

现在我想在方法中获取当前页面,请给我一些想法,谢谢。

【问题讨论】:

  • 您的页面是否基于路由器路径? computed: {currentPage(){return this.$router.query.page;}} 可以工作
  • 网址页面http://localhost.loca/product
  • 能否请您显示此组件的更多代码?尤其是代码从 api 获取数据

标签: javascript vue.js vuejs2


【解决方案1】:

您是否使用 b-pagination ,请参考此链接。 bootstrap-vue

<script>
      export default {
        data() {
          return {
            perPage: 3,
            currentPage: 1,
            items: [
              { id: 1, first_name: 'Fred', last_name: 'Flintstone' },
              { id: 2, first_name: 'Wilma', last_name: 'Flintstone' },
              { id: 3, first_name: 'Barney', last_name: 'Rubble' },
              { id: 4, first_name: 'Betty', last_name: 'Rubble' },
              { id: 5, first_name: 'Pebbles', last_name: 'Flintstone' },
              { id: 6, first_name: 'Bamm Bamm', last_name: 'Rubble' },
              { id: 7, first_name: 'The Great', last_name: 'Gazzoo' },
              { id: 8, first_name: 'Rockhead', last_name: 'Slate' },
              { id: 9, first_name: 'Pearl', last_name: 'Slaghoople' }
            ]
          }
        },
        computed: {
          rows() {
            return this.items.length
          }
        }
      }
    </script>

    <b-pagination
      v-model="currentPage"
      :total-rows="rows"
      :per-page="perPage"
      aria-controls="my-table"
    ></b-pagination>

currentPage 在您的 v-Model 中,并且与 b-table ":current-page" 中的名称一致。

 <p class="mt-3">Current Page: {{ currentPage }}</p>   

<b-table id="my-table"
      :items="items"
      :per-page="perPage"
      :current-page="currentPage"
      small
    ></b-table>

【讨论】:

  • 谢谢,但我想获取当前页面的动态而不是静态的
  • 在你的 html 中设置 v-model="currentPage" ,这是用户点击的当前页面。
  • 感谢您对我工作的帮助,太好了
猜你喜欢
  • 2020-12-01
  • 1970-01-01
  • 2011-05-07
  • 1970-01-01
  • 2012-12-04
  • 2013-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多