Skip to content

Instantly share code, notes, and snippets.

@lukecurtis93
Created February 18, 2019 08:25
Show Gist options
  • Save lukecurtis93/0bd1ef2db2e8a474292b7bcbf496022f to your computer and use it in GitHub Desktop.
Save lukecurtis93/0bd1ef2db2e8a474292b7bcbf496022f to your computer and use it in GitHub Desktop.
A Vue debounce example leveraging Lodash
<template>
<div>
<div class="col-md-6 vertical-center" v-for="(user, index) in users" :key="index">
<input type="text" @input="updateUsername(user)" class="form-control" v-model="user.name">
</div>
</div>
</template>
<script>
export default {
data() {
return {
users:[ {
'name':'[email protected]',
'id':1,
},
{
'name':'[email protected]',
'id':2,
}
]
}
},
methods: {
updateUsername: _.debounce((user) => {
axios.patch(`/api/user/${user.id}`, user).then((res) => {
swal('Updated');
})
}, 2000),
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment