Last active
September 2, 2018 04:01
-
-
Save imbolc/814cf93e446923a0bfdb7ac36742d40a to your computer and use it in GitHub Desktop.
Vue debouncing #vuejs #vue.js #debounce #throttle #throttling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div v-loading="loading"> | |
<textarea v-model="text"></textarea> | |
{{ saving ? 'saving...' : '✓' }} | |
</div> | |
</template> | |
<script> | |
export default { | |
data: () => ({ | |
text: '', | |
saving: false, | |
saveTimer: null, | |
}), | |
methods: { | |
async save () { | |
this.saving = true | |
this.saveTimer && clearTimeout(this.saveTimer) | |
this.saveTimer = setTimeout(() => { | |
this.$http.post('/some-url', { text: this.text }) | |
this.saving = false | |
}, 1000) | |
}, | |
}, | |
watch: { | |
text (val) { this.save() }, | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment