• 【常用页面记录】vue+elementUI实现搜索框+上拉加载列表


    一、代码

    1. <script>
    2. import request from '@/http/request'
    3. export default {
    4. data () {
    5. return {
    6. list: [],//列表
    7. searchText: '',//搜素内容
    8. fileName:'',//文件名称
    9. noMore: false, // 控制滚动禁用
    10. routeLoad: false, // 控制滚动禁用
    11. limit:18,
    12. page:1,
    13. }
    14. },
    15. computed: {
    16. },
    17. mounted () {
    18. this.initList()
    19. },
    20. methods:{
    21. // 滚动加载数据
    22. infiniteScroll() {
    23. this.routeLoad = true;
    24. this.page += 1; // 页码每次滚动+1
    25. this.initList();
    26. },
    27. // 初始化列表数据
    28. initList () {
    29. this.$myLoading.showLoading()
    30. let data={
    31. limit:this.limit,//条数
    32. page:this.page,//当前页码
    33. fileName:this.fileName,//文件名称
    34. }
    35. request.$http('/file/queryFileList', 'get', data).then(response => {
    36. this.$myLoading.hideLoading()
    37. if (response.code === 0) {
    38. let listData = response.data;
    39. for (let i = 0; i < listData.length; i++) {
    40. this.list.push(listData[i]);
    41. }
    42. // 如果请求回来的数据小于limit,则说明数据到底了。
    43. if (listData.length < 18) {
    44. this.noMore = true;
    45. }
    46. // 避免数据总条数是pageSize的倍数时,数据到底还会请求一次。
    47. if (this.list.length === response.count) {
    48. this.noMore = true;
    49. }
    50. this.routeLoad = false;
    51. } else {
    52. this.$msg.error(response.msg)
    53. }
    54. })
    55. },
    56. // 搜索
    57. search () {
    58. this.list = []
    59. this.page = 1
    60. this.initList()
    61. },
    62. // 点击下载图标触发
    63. handleDown (row) {
    64. console.log(row)
    65. this.$myLoading.showLoading()
    66. request.$http('/file/downloadFile', 'get', { filePath: row.FILE_PATH, fileName: row.FILE_NAME }, { responseType: "blob" }).then(response => {
    67. this.$myLoading.hideLoading()
    68. const link = document.createElement('a') // 创建a标签
    69. let blob = new Blob([response])
    70. link.style.display = 'none'
    71. link.href = URL.createObjectURL(blob) // 创建下载的链接
    72. link.setAttribute('download', row.FILE_NAME) // 给下载后的文件命名
    73. document.body.appendChild(link)
    74. link.click() // 点击下载
    75. document.body.removeChild(link) // 完成移除元素
    76. window.URL.revokeObjectURL(link.href) // 释放blob对象
    77. })
    78. },
    79. }
    80. }
    81. script>
    82. <style lang="less" scoped>
    83. .mainBox {
    84. position: absolute;
    85. top: 0;
    86. bottom: 0;
    87. left: 0;
    88. right: 0;
    89. overflow: auto;
    90. background: #f7f7f9;
    91. color: #333;
    92. font-size: 16px;
    93. .headbox {
    94. padding: 28px 20px 18px;
    95. position: fixed;
    96. width: 100%;
    97. border-radius: 6px;
    98. opacity: 1;
    99. display: flex;
    100. flex-direction: column;
    101. gap: 15px;
    102. background: #ffffff;
    103. border-bottom: 20px solid #f7f7f9;
    104. /deep/ .el-input__inner {
    105. height: 36px;
    106. border-radius: 30px;
    107. text-align: center;
    108. background: #f3f3f3;
    109. border: none;
    110. }
    111. /deep/ .el-input__prefix {
    112. // left:100px;
    113. left: 3px;
    114. }
    115. /deep/ &.on .el-input__icon {
    116. left: 100px;
    117. }
    118. /deep/ .el-input__icon {
    119. line-height: 36px;
    120. }
    121. .IconShow{
    122. /deep/ .el-icon-search:before{
    123. content:''
    124. }
    125. }
    126. }
    127. .listBox {
    128. background: #fff;
    129. height: calc(100% - 102px);
    130. overflow: auto;
    131. margin-top: 100px;
    132. .file {
    133. padding: 12px 15px;
    134. background: #ffffff;
    135. display: flex;
    136. justify-content: space-between;
    137. align-items: center;
    138. border-bottom: 1px solid #f2f2f3;
    139. /deep/ .el-button {
    140. border: 1px solid#2E74DE;
    141. color: #2e74de;
    142. font-size: 16px;
    143. }
    144. }
    145. }
    146. }
    147. style>

    二、实现效果

  • 相关阅读:
    内聚与耦合
    Flask后端开发(二) - 功能实现和项目总结
    2022年第十二届APMCM亚太地区大学生数学建模竞赛--思路&代码
    【PAT甲级】1006 Sign In and Sign Out
    CENTOS上的网络安全工具(十三)搬到Docker上(1)?
    Spark学习(3)-Spark环境搭建-Standalone
    三步搭建个人网站并发布上线【内网穿透】
    (九)DFI接口时序
    leetcode298周赛记录
    项目初始化时ApplicationRunner和CommandLineRunner的应用
  • 原文地址:https://blog.csdn.net/weixin_50863323/article/details/133738373