File tree Expand file tree Collapse file tree 4 files changed +25
-3
lines changed
directives/debounced-click Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 1+ /* eslint-disable no-unused-vars */
2+ import { DirectiveOptions } from 'vue'
3+ import _ from 'lodash'
4+
5+ const debouncedClickDirectiveOptions : DirectiveOptions = {
6+ inserted ( el , directiveBinding ) {
7+ const wait : number = directiveBinding . arg ? + directiveBinding . arg : 1000
8+ el . addEventListener ( 'click' , _ . debounce ( event => {
9+ directiveBinding . value . call ( el , event )
10+ } , wait ) )
11+ }
12+ }
13+
14+ export default debouncedClickDirectiveOptions
Original file line number Diff line number Diff line change 1+ import Vue from 'vue'
2+ import debouncedClickDirectiveOptions from './debounced-click-directive-options'
3+
4+ Vue . directive ( 'debounced-click' , debouncedClickDirectiveOptions )
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import vuetify from './plugins/vuetify'
66import 'roboto-fontface/css/roboto/roboto-fontface.css'
77import '@mdi/font/css/materialdesignicons.css'
88import '@/directives/throttled-click'
9+ import '@/directives/debounced-click'
910import { listenToColorScheme } from '@/plugins/adaptive-color-scheme'
1011
1112Vue . config . productionTip = false
Original file line number Diff line number Diff line change 3939 <v-list-item-avatar tile size =" 80" color =" grey" />
4040 </v-list-item >
4141 <v-card-actions >
42- <v-btn text v-throttled-click:2000 =" handleThrottledClickButton" >Button </v-btn >
43- <v-btn text >Button </v-btn >
42+ <v-btn text v-throttled-click:2000 =" handleThrottledClickButton" >Throttle </v-btn >
43+ <v-btn text v-debounced-click:2000 = " handleDebouncedClickButton " >Debounce </v-btn >
4444 </v-card-actions >
4545 </v-card >
4646 <v-row align =" center" >
@@ -148,7 +148,10 @@ export default Vue.extend({
148148 },
149149 methods: {
150150 handleThrottledClickButton (event : Event ) {
151- console .log (' handleThrottledClickButton' , event )
151+ console .info (' handleThrottledClickButton' , event )
152+ },
153+ handleDebouncedClickButton (event : Event ) {
154+ console .info (' handleDebouncedClickButton' , event )
152155 },
153156 onResize () {
154157 this .windowSize = { x: window .innerWidth , y: window .innerHeight }
You can’t perform that action at this time.
0 commit comments