watch:{...">
美文网首页
vue 搜素防抖

vue 搜素防抖

作者: 疯泽清 | 来源:发表于2021-03-04 16:59 被阅读0次

<el-input v-model="pointName" placeholder="请输入内容" />

 watch: {

    pointName(val) {

      this.searchLeft(this, val)

    }},

在公共组件中添加你的防抖函数

/**

 * @param {Function} func

 * @param {number} wait

 * @return {*}

 */

export function debounce(func, wait) {

  let timeout = ''

  return (v) => {

    if (timeout) {

      clearTimeout(timeout)

    }

    timeout = setTimeout(() => {

      func(v)

    }, wait)

  }

}

使用前在公共的js中引入  import { debounce } from '@/utils/index'

 searchLeft: debounce((vm) => {

      const data = vm.leftData.filter(item => item.name.indexOf(vm.pointName) !== -1)

      vm.setfilterData(data)

      vm.pointName = ''

    }, 500),

相关文章

网友评论

      本文标题:vue 搜素防抖

      本文链接:https://www.haomeiwen.com/subject/kjpkqltx.html