環境: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 },
