Skip to content

Instantly share code, notes, and snippets.

@lukecurtis93
Created February 18, 2019 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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':'user@user.com',
'id':1,
},
{
'name':'user2@user.com',
'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