Created
April 16, 2018 15:04
-
-
Save AlanJenkinsVS/73606df259a3f7df50f96f426a48e41b to your computer and use it in GitHub Desktop.
1. Smarter Watchers - Vue JS Optimisations
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
// 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