mint-ui 输入框按下按键执行查询


环境:vue、mint-ui

功能:一个输入框,按下按键之后就执行某个功能。

截图:一个输入框

输入框html:

<mt-search v-model="query" cancel-text="" placeholder="提取码">   // mt-search 
基本函数:
debounce (func, delay) {
      let timer
      return function (...args) {
        if (timer) {
          clearTimeout(timer)
        }
        timer = setTimeout(() => {
          func.apply(this, args)
        }, delay)
      }
    }

查询函数:

getData () {
  console.log('执行查询。。。。。。')
},

主要函数:

1 created() {
2     this.$watch('query', this.debounce(newQuery => {
3       if (newQuery) {
4         setTimeout(() => {
5           this.getData()
6         }, 20)
7       }
8     }, 200))
9   },

 

 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM