v-hotkey icon indicating copy to clipboard operation
v-hotkey copied to clipboard

Vue 3 Support

Open fatalis opened this issue 4 years ago • 4 comments

here's a way to use in Vue 3 in the mean time if anyone needs this:

app.directive('hotkey', {
  beforeMount: VueHotkey.directive.bind,
  updated: VueHotkey.directive.componentUpdated,
  unmounted: VueHotkey.directive.unbind,
});

fatalis avatar Aug 30 '20 19:08 fatalis

Still not working, see images image image image

ayophanz avatar Mar 22 '21 06:03 ayophanz

work for me :

main.ts

 app.directive('hotkey', {
    beforeMount: VueHotkey.directive.bind,
    updated: VueHotkey.directive.componentUpdated,
    unmounted: VueHotkey.directive.unbind,
  }); 

file.vue

data() {
  return {
     searchPanel: false,
  }
},
methods: {
   showSearch() {
      console.log('opened')
      this.searchPanel = !this.searchPanel
    }
  },
  computed: {
    openSearch() {
      return {
        'ctrl+f: { 
          keyup: this.showSearch
        }
      }
    }
  }
<span v-show="searchPanel" v-hotkey.prevent='openSearch'>Blabla</span>

note : v-hotkey as attr and openSearch (computed)

Nihilop avatar May 03 '21 06:05 Nihilop

I have this working in vue3, but my tests that use the directive fail.

[Vue warn]: Failed to resolve directive: hotkey at <Anonymous ref="VTU_COMPONENT" > at <VTUROOT>

scott-fryxell avatar Oct 16 '21 13:10 scott-fryxell

Published a fork in the meantime https://github.com/wobsoriano/v-hotkey3

With added useHotkey composable.

wobsoriano avatar Dec 13 '22 20:12 wobsoriano