vue 实现搜索历史_vue中节流函数实现搜索数据

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

基本代码如下

model.trim="keyword">

查看

删除

基本代码如下

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

})

},

}

}

原文:https://www.cnblogs.com/smart-girl/p/12605728.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值