Skip to content

Instantly share code, notes, and snippets.

@AlanJenkinsVS
Created April 16, 2018 15:04
Show Gist options
  • Save AlanJenkinsVS/73606df259a3f7df50f96f426a48e41b to your computer and use it in GitHub Desktop.
Save AlanJenkinsVS/73606df259a3f7df50f96f426a48e41b to your computer and use it in GitHub Desktop.
1. Smarter Watchers - Vue JS Optimisations
// Typical pattern
created() {
this.fetchUserList();
},
watch: {
searchText() {
this.fetchUserList();
}
}
// Optimization - Watchers accept method names
watch: {
searchText: 'fetchUserList'
}
// Optimization - invoke a watcher immediately, note this uses object syntax
watch: {
searchText: {
handler: 'fetchUserList',
immediate: true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment