То, что вы ищете, называется противодействием. И это просто таймер, который ждет, когда вы перестанете нажимать клавиши.
Вот быстрый способ сделать это с помощью loda sh debounce
template:
<input
:value="input"
@change="evt=>textChange(evt.target.value)"
@input="evt=>textEntry(evt.target.value)"
/>
javascript:
Импорт:
import { debounce } from 'lodash'
Определение:
model: {
prop: 'input',
event: 'input'
},
props: {
input: {
default: '',
type: String
},
debounce: {
default: -1,
type: Number
}
},
methods: {
textChange (value) {
this.$emit('input', value)
}
},
textEntry (value) {
// This is to cover for situations where the change event runs first
if (value.toUpperCase() === this.input.toUpperCase()) return
if (this.debounce >= 0) {
this.emitValue(value)
} else {
this.$emit('input', value)
}
}
},
async mounted () {
this.emitValue = debounce(value => {
this.$emit('input', value)
}, Math.abs(this.debounce))
await this.$nextTick()
this.textChange(this.input) // apply whatever was loaded, and allow bindings to run
}