前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >关于vue项目中搜索节流的实现

关于vue项目中搜索节流的实现

作者头像
马克社区
发布2022-06-07 15:20:19
3440
发布2022-06-07 15:20:19
举报
文章被收录于专栏:高端IT高端IT

我们经常会遇到这种需求,现在我们在使用百度搜索的时候他们的思想也是 根据防抖节流而实现的,至于用防抖还是节流根据自己需求。

代码语言:javascript
复制
<template>
 <input type="text"   v-model.trim="sse">
</template>
<script>
const delay = (function () {
  let timer = 0
  return function (callback, ms) {
    clearTimeout(timer)
    timer = setTimeout(callback, ms)
  }
})()
export default {
    name :  'search',
    watch : {
        sse () {
     delay(() => {
        this.search()
      }, 500)
},
methods :{
    search () {
        this.$axios
          .get([url])
          .then(response => {
            // success
          })
          .catch(error => {
            // error
            alert('失败!')
          })
}
}
}
}

</script>

更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/119809210

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档