需求:
客户要求每页几天改为手动输入,不想用固定的条数。
思路:
将下拉框选择的条数改为el-input输入框,当焦点离开输入框后,调搜索查询的接口即可。
上代码:
html:
<div style="display: flex;">
<el-pagination
@size-change="sizeChange"
@current-change="pageChanges"
:current-page="mixinsPage.page"
:page-size="pageWant"
style="margin-top: 8px;"
layout="total, prev, pager, next"
:total="mixinsPage.count">
</el-pagination>
<el-input
v-model.number="pageWant"
style="margin-top: 8px;width: 100px;"
placeholder="请输入条数"
@change="pageInputChange"
@input="inputChange">
</el-input>
<div class="pages"> 条 / 页</div>
</div>
js:
data() {
pageWant: 10, // 默认给个10条每页
size: 10,
page: 0
},
mounted(){
if (sessionStorage.getItem("pagesChangeWs")) {
this.pageWant = Number(sessionStorage.getItem("pagesChangeWs"))
} else {
this.pageWant = 10
}
this.size = this.pageWant
this.getList()
},
methods: {
pageChanges(val) {
this.page = val
this.getList() // 搜索查询的方法
},
sizeChange(e) {
this.page = 0
this.size = e
this.init()
},
pageInputChange(val) {
this.mixinsPage.size = val
this.getList()
let pageList = []
pageList.push(val)
sessionStorage.setItem("pagesChangeWs",pageList)
},
inputChange(val) {
if (!val) {
this.$message.error('每页显示的条数不能为空,请输入想显示的条数!', 3)
}
},
},
css:
.pages{
color: #606266;
font-size: 15px;
margin: 15px 0 0 8px;
font-family: Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Arial,sans-serif;
}