分页实现但是表格不刷新?
分页:
<el-table :data="tableData"
border
fit
highlight-current-row
style="width: 100%"
>
<el-table-column
v-for="(item, i) in cols"
:key="i"
align="center"
:prop="item.prop"
:label="item.label"
>
</el-table-column>
</el-table>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="currentPage"
:page-sizes="[1, 2, 3, 4]"
:page-size="pagesize"
layout="total, sizes, prev, pager, next, jumper"
:total="getTotal">
</el-pagination>
data:
data () { return {
tableData: [],
cols: [],
currentPage: 1,
pagesize: 1
}
},
分页方法:
handleSizeChange (val) { console.log(`每页 ${val} 条`)
this.pagesize = val
this.getData()
},
handleCurrentChange (val) {
console.log(`当前页: ${val}`)
this.currentPage = val
this.getData()
}
回答:
应该是tableData赋值了ui没有刷新问题,可以使用this.$set()赋值试试
this.$set(this,'tableData',response) //这里是伪代码,具体索引+1或-1需要自己操作
const num = currentpage-1 * pagesize
if(num + pagesize >= response.length){
this.$set(this,'tableData',response.slice(num,response.length))
}else{
this.$set(this,'tableData',response.slice(num,num + pagesize))
}
以上是 分页实现但是表格不刷新? 的全部内容, 来源链接: utcz.com/p/934996.html