element-ui的分页只有固定的页数选择,我们可以对其进行封装,变成自定义输入进行分页.
    效果如下:
    image.png
    代码如下:

    1. <template>
    2. <div class="sui-pagination">
    3. <div class="page-input">
    4. <span>每页显示</span>
    5. <el-input
    6. class="small"
    7. style="padding:0 5px;"
    8. type="number"
    9. min="0"
    10. v-model.number="inputNum"
    11. @keyup.enter.native="setPage"
    12. ></el-input>
    13. <span>条,输入后按回车键</span>
    14. </div>
    15. <el-pagination
    16. :background="true"
    17. :current-page="params.pageNo"
    18. layout="total, prev, pager, next, jumper"
    19. :page-size="params.pageSize"
    20. :total="total"
    21. @current-change="handleCurrentChange"
    22. @size-change="handleSizeChange"
    23. style="text-align:right;"
    24. ></el-pagination>
    25. </div>
    26. </template>
    27. <script>
    28. export default {
    29. name:"sui-pagination",
    30. props:{
    31. total:{
    32. type:Number,
    33. default:0
    34. },
    35. params: {
    36. type:Object,
    37. default:{
    38. pageNo:1,
    39. pageSize:10
    40. }
    41. }
    42. },
    43. data() {
    44. return {
    45. inputNum: 10, // 默认输入的条数
    46. }
    47. },
    48. methods: {
    49. setPage(event) {
    50. let num = event.target.value
    51. let re = /^[0-9]+$/ // 做一下数据过滤
    52. let state = re.test(num)
    53. if (state) {
    54. this.handleSizeChange(num);
    55. } else {
    56. this.handleSizeChange(this.inputNum);
    57. }
    58. },
    59. handleCurrentChange(val) {
    60. this.$emit('change', {
    61. pageNo:val,
    62. pageSize:this.params.pageSize
    63. })
    64. },
    65. handleSizeChange(val) {
    66. this.$emit('change', {
    67. pageNo:this.params.pageNo,
    68. pageSize:val
    69. })
    70. }
    71. },
    72. }
    73. </script>
    74. <style lang="scss" scoped>
    75. .sui-pagination {
    76. display: flex;
    77. }
    78. .page-input {
    79. display: inline-block;
    80. display: flex;
    81. align-items: center;
    82. margin:15px 35px 0px 0px;
    83. > span {
    84. display: inline-block;
    85. color: #8a8e98;
    86. font-size: 14px;
    87. user-select: none;
    88. white-space: nowrap;
    89. }
    90. .small {
    91. width: 78px;
    92. padding: 0 5px;
    93. }
    94. }
    95. </style>

    使用方法:

    1. <sui-pagination
    2. class="width-47"
    3. :total="total"
    4. :params="params"
    5. @change="pageChanges">
    6. </sui-pagination>
    7. params:{
    8. pageNo:,
    9. pageSize:,
    10. ...
    11. }
    12. total:总数
    13. pageChanges(params) {
    14. this.params.pageNo = params.pageNo;
    15. this.params.pageSize = params.pageSize;
    16. this.fetchData(); // 执行接口分页查询
    17. },