首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让vue-good-table每5秒自动转到下一页?

如何让vue-good-table每5秒自动转到下一页?
EN

Stack Overflow用户
提问于 2019-04-03 00:54:48
回答 1查看 1.1K关注 0票数 0

这是他们的一个教程中的一个vue-good-table的例子,但我希望能够让它每隔5秒转到下一页,然后在结束时重新启动pg1。怎么可能做到这一点呢?

HTML:

代码语言:javascript
复制
<div id="app">
<vue-good-table
:columns="columns"
:rows="rows"
:pagination-options="{ enabled: true, perPage: 5}"
:search-options="{ enabled: true}"> 
</vue-good-table>                  
</div>

JS:

代码语言:javascript
复制
new Vue({
  el: '#app',
  data() {
    return {
      columns: [
        {
          label: 'Name',
          field: 'name',
        },
        {
          label: 'Age',
          field: 'age',
          type: 'number',
        },
        {
          label: 'Created On',
          field: 'createdAt',
          type: 'date',
          dateInputFormat: 'YYYY-MM-DD',
          dateOutputFormat: 'MMM Do YY',
        },
        {
          label: 'Percent',
          field: 'score',
          type: 'percentage',
        },
      ],
      rows: [
        { id:1, name:"John", age: 20, createdAt: '201-10-31:9: 35 am',score: 0.03343 },
        { id:2, name:"Jane", age: 24, createdAt: '2011-10-31', score: 0.03343 },
        { id:3, name:"Susan", age: 16, createdAt: '2011-10-30', score: 0.03343 },
        { id:4, name:"Chris", age: 55, createdAt: '2011-10-11', score: 0.03343 },
        { id:5, name:"Dan", age: 40, createdAt: '2011-10-21', score: 0.03343 },
        { id:6, name:"John", age: 20, createdAt: '2011-10-31', score: 0.03343 },
        { id:7, name:"Jane", age: 24, createdAt: '2013-09-21' },
        { id:8, name:"Susan", age: 16, createdAt: '2013-10-31', score: 0.03343 },
      ],
    };
  },
});

https://jsfiddle.net/aks9800/57a2a4ce/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-03 01:22:03

更新的提琴:https://jsfiddle.net/4hfrtL5q/

data中设置分页

代码语言:javascript
复制
pagination: {
        enabled: true,
        perPage: 3,
        setCurrentPage: 1
      }

pagination-options属性传递给组件。

代码语言:javascript
复制
  <vue-good-table :columns="columns" :rows="rows" :pagination-options="pagination" :search-options="{ enabled: true}">

setinterval 5秒以更新mounted中的pagination.setCurrentPage

代码语言:javascript
复制
  mounted() {

    setInterval(() => {
      let count = this.rows.length,
        perpage = this.pagination.perPage,
        currentpage = this.pagination.setCurrentPage
        this.pagination.setCurrentPage = count / perpage > currentpage ? currentpage + 1 : 1
    }, 5000)
  },
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55479949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档