zoukankan      html  css  js  c++  java
  • vue中节流函数实现搜索数据

    在日常开发中有很多场景我们都需要用到节流函数和防抖函数,比如:实现输入框的模糊查询因为需要轮询ajax,影响浏览器性能,所以需要用到节流函数;实现手机号、姓名之类的的验证,往往我们只需要验证一次,这个时候我们就需要用到防抖函数;但是网上的很多资料都是不够具体和便于理解。
    基本代码如下

     <el-input placeholder="请输入搜索内容" suffix-icon="el-icon-search" class="searchItem searchInput" v-        
        model.trim="keyword">
    </el-input>
         <div class="taskList">
            <el-table ref="multipleTable" :data="userListData.rows" id="taskList" tooltip-effect="dark" v-loading="loading" element-loading-text="数据加载中" element-loading-background="rgba(0, 0, 0, 0.6)" style=" 100%" border fit stripe>
              <el-table-column type="index" :index="indexMethod" label="序号" width="60">
              </el-table-column>
              <el-table-column prop="name" label="名称" show-overflow-tooltip>
              </el-table-column>
              <el-table-column prop="address" label="地址" show-overflow-tooltip>
              </el-table-column>
              <el-table-column prop="phone" label="电话" show-overflow-tooltip>
              </el-table-column>
              <el-table-column prop="principal" label="负责人" show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="操作" width="200">
                <template slot-scope="scope">
                  <el-button type="success" size="small" plain @click="goDetail(scope.row.id)" v-if="menus.USER_CUST_VIEW">查看</el-button>
                  <!-- <el-button type="primary" size="small" plain @click="goUrl(`/zz/editUser/u/${scope.row.userId}`)">编辑</el-button> -->
                  <el-button type="danger" size="small" plain @click="removeUser(scope.row.id)" >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="userListData.pageNumber" :page-sizes="[10,20,30, 50]" :page-size="userListData.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="userListData.total">
            </el-pagination>
          </div>
    

    基本代码如下

    import _ from 'lodash'
    export default{
        computed:{
    searchContent() {
          return this.keyword
        },
      watch: {
        // 如果 `question` 发生改变,这个函数就会运行
        searchContent: function(newQuestion, oldQuestion) {
          this.userListData.pageNumber = 1
          this.getAccountUserListDebounce()
        }
      },
        getAccountUserListDebounce: _.debounce(
          function() {
            this.getList()
          },
          // 这是我们为判定用户停止输入等待的毫秒数
          500
        ),
        getList() {
          this.loading = true
          mytomer(this.keyword, this.userListData.pageSize, this.userListData.pageNumber, null).then(res => {
            this.loading = false
            this.userListData.total = res.data.total
            this.userListData.rows = res.data.rows
          }).catch(error => {
            this.loading = false
          })
        },
    
    }
    

    }

  • 相关阅读:
    适配器模式
    显示实现接口
    Mysql表引擎的切换
    Mysql事务隔离级别
    按照指定的格式解析字节数组
    委托和事件的简单实用
    C#压缩和解压缩字节(GZip)
    Mysql数据库批量添加数据
    常用的分页类
    保证依赖的服务已全部启动
  • 原文地址:https://www.cnblogs.com/smart-girl/p/12605728.html
Copyright © 2011-2022 走看看