• vue element 搜索框根据后台的接口实现模糊查询 + 分页特殊处理+重置表格


    模糊查询效果图
    在这里插入图片描述

    1.配置接口 search: "/api/goods/search", //搜索接口/goods/search
    2.get接口
    search(params) { return axios.get(base.search, { params });//后台传参 再写这个params },
    3.异步请求接口

      // 搜索接口
        async search(search){
            let res = await this.$api.search({search})
            console.log('搜索接口---',res.data);
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    查询事件

     onSubmit() {
            console.log('submit!',this.formInline.name);
            this.search(this.formInline.name)//查询根据后台的接口(返回查询的name)
          },
    
    • 1
    • 2
    • 3
    • 4

    4.请求到接口 那就让列表数据跟着变动

      // 搜索接口
        async search(search){
            let res = await this.$api.search({search})
            console.log('搜索接口---',res.data);
            if(res.data.status === 200){//根据后台返回 如果有就更新列表 如果没有就返回空
                this.tableData = res.data.result;
            }else{//查无数据
                this.tableData = []
                }
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    5.如果不搜索了怎么让表格数据显示到第一页 给 input加一个焦点事件 鼠标移除 表格列表数据就返回第一页

       blur(){
            if(!this.formInline.name){//如果不搜索 那就返回首页数据  
                this.projectList(1)//1就是首页
            }
    
    • 1
    • 2
    • 3
    • 4

    6.如果查询数据 分页也要跟着变化 在搜索查询接口里边去写

     // 搜索接口
        async search(search){
            let res = await this.$api.search({search})
            console.log('搜索接口---',res.data);
            if(res.data.status === 200){//根据后台返回 如果有就更新列表 如果没有就返回空
                this.tableData = res.data.result;
                this.total=res.data.result.length;//分页
                this.pageSize =res.data.result.length;//分页
            }else{//查无数据
                this.tableData = []
                this.total = 1
                this.pageSize = 1
                }
            }
        },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    总代码

        
                
                    
                
                
                    查询
                
                
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    初始化

     formInline: {
              name: '',
            },
    
    • 1
    • 2
    • 3

    请求查询接口 + 查询事件+焦点事件

     // 搜索接口
        async search(search){
            let res = await this.$api.search({search})
            console.log('搜索接口---',res.data);
            if(res.data.status === 200){//根据后台返回 如果有就更新列表 如果没有就返回空
                this.tableData = res.data.result;
                this.total=res.data.result.length;
                this.pageSize =res.data.result.length;
            }else{//查无数据
                this.tableData = []
                this.total = 1
                this.pageSize = 1
                }
            }
        },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    //查询事件
      onSubmit() {
            console.log('submit!',this.formInline.name);
            this.search(this.formInline.name)//查询根据后台的接口(返回查询的name)
          },
    
    • 1
    • 2
    • 3
    • 4
    • 5
     //   查询焦点事件
        blur(){
            if(!this.formInline.name){//如果不搜索 那就返回首页数据
                this.projectList(1)
            }
        },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    总结:K8S指标与Prometheus实现
    自定义类使用ArrayList中的remove
    Spring循环依赖
    Linux实训——单机版聊天室
    手机运行内存大揭秘:探索你手机的超级大脑!
    机器学习笔记 - 简单了解模式识别
    verilog 内置语句
    Centos8安装docker并配置Kali Linux图形化界面
    基于megengine实现YoloX【附部分源码】
    conda虚拟环境配置
  • 原文地址:https://blog.csdn.net/qq_48203828/article/details/133103125