Created
February 18, 2019 08:25
-
-
Save lukecurtis93/0bd1ef2db2e8a474292b7bcbf496022f to your computer and use it in GitHub Desktop.
A Vue debounce example leveraging Lodash
This file contains 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> | |
<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