ElementUI的表格要求的数据类型为字典数组。我使用了python3写后端,那么从数据库取数据时添加一行cursorclass=pymysql.cursors.DictCursor即可。取出后我将其存入redis数据库方便之后取用。取用时使用eval()函数再传到前端即可。
前端放置Pagination 分页器,我这里直接采用了完整功能的分页器。
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[10, 20, 50, 100]"
:page-size="pagesize"
layout="total, sizes, prev, pager, next, jumper"
:total="data.length">
</el-pagination>
其中:
handleSizeChange为pagesize发生改变时的相应函数,handleCurrentChange为currentPage发生改变时的相应函数。
page-sizes为所有可选择的page-size。可以自己更改其中的数字。
layout为附带的功能,一般不用动它。
total为总数据数。由于是字典数组,直接使用leng