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