这是他们的一个教程中的一个vue-good-table的例子,但我希望能够让它每隔5秒转到下一页,然后在结束时重新启动pg1。怎么可能做到这一点呢?
HTML:
<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:
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 },
],
};
},
});发布于 2019-04-03 01:22:03
更新的提琴:https://jsfiddle.net/4hfrtL5q/
在data中设置分页
pagination: {
enabled: true,
perPage: 3,
setCurrentPage: 1
}将pagination-options属性传递给组件。
<vue-good-table :columns="columns" :rows="rows" :pagination-options="pagination" :search-options="{ enabled: true}">setinterval 5秒以更新mounted中的pagination.setCurrentPage
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)
},https://stackoverflow.com/questions/55479949
复制相似问题